diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 52b37c1..5161e02 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -32,7 +32,8 @@ * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. * @param [batchSize=15000] {number} Number of particles per batch. */ -class ParticleContainer extends core.Container { +class ParticleContainer extends core.Container +{ constructor(maxSize, properties, batchSize) { super(); @@ -330,4 +331,4 @@ } -module.exports = ParticleContainer; +export default ParticleContainer; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 52b37c1..5161e02 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -32,7 +32,8 @@ * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. * @param [batchSize=15000] {number} Number of particles per batch. */ -class ParticleContainer extends core.Container { +class ParticleContainer extends core.Container +{ constructor(maxSize, properties, batchSize) { super(); @@ -330,4 +331,4 @@ } -module.exports = ParticleContainer; +export default ParticleContainer; diff --git a/src/particles/index.js b/src/particles/index.js index 68d4dc7..657a984 100644 --- a/src/particles/index.js +++ b/src/particles/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import ParticleContainer from './ParticleContainer'; +import ParticleRenderer from './webgl/ParticleRenderer'; /** * @namespace PIXI.particles */ -module.exports = { - ParticleContainer: require('./ParticleContainer'), - ParticleRenderer: require('./webgl/ParticleRenderer') +export default { + ParticleContainer, + ParticleRenderer }; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 52b37c1..5161e02 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -32,7 +32,8 @@ * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. * @param [batchSize=15000] {number} Number of particles per batch. */ -class ParticleContainer extends core.Container { +class ParticleContainer extends core.Container +{ constructor(maxSize, properties, batchSize) { super(); @@ -330,4 +331,4 @@ } -module.exports = ParticleContainer; +export default ParticleContainer; diff --git a/src/particles/index.js b/src/particles/index.js index 68d4dc7..657a984 100644 --- a/src/particles/index.js +++ b/src/particles/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import ParticleContainer from './ParticleContainer'; +import ParticleRenderer from './webgl/ParticleRenderer'; /** * @namespace PIXI.particles */ -module.exports = { - ParticleContainer: require('./ParticleContainer'), - ParticleRenderer: require('./webgl/ParticleRenderer') +export default { + ParticleContainer, + ParticleRenderer }; diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index ecbd63d..6808183 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../core/utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../core/utils/createIndicesForQuads'; /** * @author Mat Groves @@ -19,7 +19,8 @@ * @private * @memberof PIXI */ -class ParticleBuffer { +class ParticleBuffer +{ constructor(gl, properties, dynamicPropertyFlags, size) { /** @@ -228,4 +229,4 @@ } -module.exports = ParticleBuffer; +export default ParticleBuffer; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 52b37c1..5161e02 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -32,7 +32,8 @@ * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. * @param [batchSize=15000] {number} Number of particles per batch. */ -class ParticleContainer extends core.Container { +class ParticleContainer extends core.Container +{ constructor(maxSize, properties, batchSize) { super(); @@ -330,4 +331,4 @@ } -module.exports = ParticleContainer; +export default ParticleContainer; diff --git a/src/particles/index.js b/src/particles/index.js index 68d4dc7..657a984 100644 --- a/src/particles/index.js +++ b/src/particles/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import ParticleContainer from './ParticleContainer'; +import ParticleRenderer from './webgl/ParticleRenderer'; /** * @namespace PIXI.particles */ -module.exports = { - ParticleContainer: require('./ParticleContainer'), - ParticleRenderer: require('./webgl/ParticleRenderer') +export default { + ParticleContainer, + ParticleRenderer }; diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index ecbd63d..6808183 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../core/utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../core/utils/createIndicesForQuads'; /** * @author Mat Groves @@ -19,7 +19,8 @@ * @private * @memberof PIXI */ -class ParticleBuffer { +class ParticleBuffer +{ constructor(gl, properties, dynamicPropertyFlags, size) { /** @@ -228,4 +229,4 @@ } -module.exports = ParticleBuffer; +export default ParticleBuffer; diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index b416c1c..8fe6acf 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - ParticleShader = require('./ParticleShader'), - ParticleBuffer = require('./ParticleBuffer'); +import core from '../../core'; +import ParticleShader from './ParticleShader'; +import ParticleBuffer from './ParticleBuffer'; /** * @author Mat Groves @@ -20,7 +20,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class ParticleRenderer extends core.ObjectRenderer { +class ParticleRenderer extends core.ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -426,6 +427,6 @@ } -module.exports = ParticleRenderer; +export default ParticleRenderer; core.WebGLRenderer.registerPlugin('particle', ParticleRenderer); diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 52b37c1..5161e02 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -32,7 +32,8 @@ * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. * @param [batchSize=15000] {number} Number of particles per batch. */ -class ParticleContainer extends core.Container { +class ParticleContainer extends core.Container +{ constructor(maxSize, properties, batchSize) { super(); @@ -330,4 +331,4 @@ } -module.exports = ParticleContainer; +export default ParticleContainer; diff --git a/src/particles/index.js b/src/particles/index.js index 68d4dc7..657a984 100644 --- a/src/particles/index.js +++ b/src/particles/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import ParticleContainer from './ParticleContainer'; +import ParticleRenderer from './webgl/ParticleRenderer'; /** * @namespace PIXI.particles */ -module.exports = { - ParticleContainer: require('./ParticleContainer'), - ParticleRenderer: require('./webgl/ParticleRenderer') +export default { + ParticleContainer, + ParticleRenderer }; diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index ecbd63d..6808183 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../core/utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../core/utils/createIndicesForQuads'; /** * @author Mat Groves @@ -19,7 +19,8 @@ * @private * @memberof PIXI */ -class ParticleBuffer { +class ParticleBuffer +{ constructor(gl, properties, dynamicPropertyFlags, size) { /** @@ -228,4 +229,4 @@ } -module.exports = ParticleBuffer; +export default ParticleBuffer; diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index b416c1c..8fe6acf 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - ParticleShader = require('./ParticleShader'), - ParticleBuffer = require('./ParticleBuffer'); +import core from '../../core'; +import ParticleShader from './ParticleShader'; +import ParticleBuffer from './ParticleBuffer'; /** * @author Mat Groves @@ -20,7 +20,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class ParticleRenderer extends core.ObjectRenderer { +class ParticleRenderer extends core.ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -426,6 +427,6 @@ } -module.exports = ParticleRenderer; +export default ParticleRenderer; core.WebGLRenderer.registerPlugin('particle', ParticleRenderer); diff --git a/src/particles/webgl/ParticleShader.js b/src/particles/webgl/ParticleShader.js index 684413b..5127bdb 100644 --- a/src/particles/webgl/ParticleShader.js +++ b/src/particles/webgl/ParticleShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI * @param gl {PIXI.Shader} The webgl shader manager this shader works for. */ -class ParticleShader extends Shader { +class ParticleShader extends Shader +{ constructor(gl) { super( @@ -60,4 +61,4 @@ } } -module.exports = ParticleShader; +export default ParticleShader; diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 52b37c1..5161e02 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -32,7 +32,8 @@ * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. * @param [batchSize=15000] {number} Number of particles per batch. */ -class ParticleContainer extends core.Container { +class ParticleContainer extends core.Container +{ constructor(maxSize, properties, batchSize) { super(); @@ -330,4 +331,4 @@ } -module.exports = ParticleContainer; +export default ParticleContainer; diff --git a/src/particles/index.js b/src/particles/index.js index 68d4dc7..657a984 100644 --- a/src/particles/index.js +++ b/src/particles/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import ParticleContainer from './ParticleContainer'; +import ParticleRenderer from './webgl/ParticleRenderer'; /** * @namespace PIXI.particles */ -module.exports = { - ParticleContainer: require('./ParticleContainer'), - ParticleRenderer: require('./webgl/ParticleRenderer') +export default { + ParticleContainer, + ParticleRenderer }; diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index ecbd63d..6808183 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../core/utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../core/utils/createIndicesForQuads'; /** * @author Mat Groves @@ -19,7 +19,8 @@ * @private * @memberof PIXI */ -class ParticleBuffer { +class ParticleBuffer +{ constructor(gl, properties, dynamicPropertyFlags, size) { /** @@ -228,4 +229,4 @@ } -module.exports = ParticleBuffer; +export default ParticleBuffer; diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index b416c1c..8fe6acf 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - ParticleShader = require('./ParticleShader'), - ParticleBuffer = require('./ParticleBuffer'); +import core from '../../core'; +import ParticleShader from './ParticleShader'; +import ParticleBuffer from './ParticleBuffer'; /** * @author Mat Groves @@ -20,7 +20,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class ParticleRenderer extends core.ObjectRenderer { +class ParticleRenderer extends core.ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -426,6 +427,6 @@ } -module.exports = ParticleRenderer; +export default ParticleRenderer; core.WebGLRenderer.registerPlugin('particle', ParticleRenderer); diff --git a/src/particles/webgl/ParticleShader.js b/src/particles/webgl/ParticleShader.js index 684413b..5127bdb 100644 --- a/src/particles/webgl/ParticleShader.js +++ b/src/particles/webgl/ParticleShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI * @param gl {PIXI.Shader} The webgl shader manager this shader works for. */ -class ParticleShader extends Shader { +class ParticleShader extends Shader +{ constructor(gl) { super( @@ -60,4 +61,4 @@ } } -module.exports = ParticleShader; +export default ParticleShader; diff --git a/src/prepare/canvas/CanvasPrepare.js b/src/prepare/canvas/CanvasPrepare.js index b8a3682..ac5cc9d 100644 --- a/src/prepare/canvas/CanvasPrepare.js +++ b/src/prepare/canvas/CanvasPrepare.js @@ -1,4 +1,4 @@ -let core = require('../../core'); +import core from '../../core'; /** * Prepare uploads elements to the GPU. The CanvasRenderer version of prepare @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasPrepare { +class CanvasPrepare +{ constructor() { } @@ -53,9 +54,8 @@ destroy() { } - } -module.exports = CanvasPrepare; - core.CanvasRenderer.registerPlugin('prepare', CanvasPrepare); + +export default CanvasPrepare; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 52b37c1..5161e02 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -32,7 +32,8 @@ * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. * @param [batchSize=15000] {number} Number of particles per batch. */ -class ParticleContainer extends core.Container { +class ParticleContainer extends core.Container +{ constructor(maxSize, properties, batchSize) { super(); @@ -330,4 +331,4 @@ } -module.exports = ParticleContainer; +export default ParticleContainer; diff --git a/src/particles/index.js b/src/particles/index.js index 68d4dc7..657a984 100644 --- a/src/particles/index.js +++ b/src/particles/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import ParticleContainer from './ParticleContainer'; +import ParticleRenderer from './webgl/ParticleRenderer'; /** * @namespace PIXI.particles */ -module.exports = { - ParticleContainer: require('./ParticleContainer'), - ParticleRenderer: require('./webgl/ParticleRenderer') +export default { + ParticleContainer, + ParticleRenderer }; diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index ecbd63d..6808183 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../core/utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../core/utils/createIndicesForQuads'; /** * @author Mat Groves @@ -19,7 +19,8 @@ * @private * @memberof PIXI */ -class ParticleBuffer { +class ParticleBuffer +{ constructor(gl, properties, dynamicPropertyFlags, size) { /** @@ -228,4 +229,4 @@ } -module.exports = ParticleBuffer; +export default ParticleBuffer; diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index b416c1c..8fe6acf 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - ParticleShader = require('./ParticleShader'), - ParticleBuffer = require('./ParticleBuffer'); +import core from '../../core'; +import ParticleShader from './ParticleShader'; +import ParticleBuffer from './ParticleBuffer'; /** * @author Mat Groves @@ -20,7 +20,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class ParticleRenderer extends core.ObjectRenderer { +class ParticleRenderer extends core.ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -426,6 +427,6 @@ } -module.exports = ParticleRenderer; +export default ParticleRenderer; core.WebGLRenderer.registerPlugin('particle', ParticleRenderer); diff --git a/src/particles/webgl/ParticleShader.js b/src/particles/webgl/ParticleShader.js index 684413b..5127bdb 100644 --- a/src/particles/webgl/ParticleShader.js +++ b/src/particles/webgl/ParticleShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI * @param gl {PIXI.Shader} The webgl shader manager this shader works for. */ -class ParticleShader extends Shader { +class ParticleShader extends Shader +{ constructor(gl) { super( @@ -60,4 +61,4 @@ } } -module.exports = ParticleShader; +export default ParticleShader; diff --git a/src/prepare/canvas/CanvasPrepare.js b/src/prepare/canvas/CanvasPrepare.js index b8a3682..ac5cc9d 100644 --- a/src/prepare/canvas/CanvasPrepare.js +++ b/src/prepare/canvas/CanvasPrepare.js @@ -1,4 +1,4 @@ -let core = require('../../core'); +import core from '../../core'; /** * Prepare uploads elements to the GPU. The CanvasRenderer version of prepare @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasPrepare { +class CanvasPrepare +{ constructor() { } @@ -53,9 +54,8 @@ destroy() { } - } -module.exports = CanvasPrepare; - core.CanvasRenderer.registerPlugin('prepare', CanvasPrepare); + +export default CanvasPrepare; \ No newline at end of file diff --git a/src/prepare/index.js b/src/prepare/index.js index 962e362..066a4a6 100644 --- a/src/prepare/index.js +++ b/src/prepare/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLPrepare'; +import canvas from './canvas/CanvasPrepare'; -module.exports = { - webGL: require('./webgl/WebGLPrepare'), - canvas: require('./canvas/CanvasPrepare') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/accessibility/AccessibilityManager.js b/src/accessibility/AccessibilityManager.js index 021325d..ea420a0 100644 --- a/src/accessibility/AccessibilityManager.js +++ b/src/accessibility/AccessibilityManager.js @@ -1,5 +1,5 @@ -let core = require('../core'); -let Device = require('ismobilejs'); +import core from '../core'; +import Device from 'ismobilejs'; // add some extra variables to the container.. Object.assign( @@ -15,7 +15,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer|PIXI.WebGLRenderer} A reference to the current renderer */ -class AccessibilityManager { +class AccessibilityManager +{ constructor(renderer) { if(Device.tablet || Device.phone) @@ -447,7 +448,7 @@ } } -module.exports = AccessibilityManager; - core.WebGLRenderer.registerPlugin('accessibility', AccessibilityManager); core.CanvasRenderer.registerPlugin('accessibility', AccessibilityManager); + +export default AccessibilityManager; \ No newline at end of file diff --git a/src/accessibility/accessibleTarget.js b/src/accessibility/accessibleTarget.js index b6f5aba..34847fe 100644 --- a/src/accessibility/accessibleTarget.js +++ b/src/accessibility/accessibleTarget.js @@ -12,7 +12,7 @@ * PIXI.accessibility.accessibleTarget * ); */ -let accessibleTarget = { +const accessibleTarget = { /** * Flag for if the object is accessible. If true AccessibilityManager will overlay a @@ -54,4 +54,4 @@ }; -module.exports = accessibleTarget; +export default accessibleTarget; \ No newline at end of file diff --git a/src/accessibility/index.js b/src/accessibility/index.js index f69d612..ab40119 100644 --- a/src/accessibility/index.js +++ b/src/accessibility/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI accessibility library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import accessibleTarget from './accessibleTarget'; +import AccessibilityManager from './AccessibilityManager'; /** * @namespace PIXI.AccessibilityManager */ -module.exports = { - accessibleTarget: require('./accessibleTarget'), - AccessibilityManager: require('./AccessibilityManager') -}; +export default { + accessibleTarget, + AccessibilityManager +}; \ No newline at end of file diff --git a/src/core/Shader.js b/src/core/Shader.js index 7b60603..c390cc2 100644 --- a/src/core/Shader.js +++ b/src/core/Shader.js @@ -1,15 +1,21 @@ -let GLShader = require('pixi-gl-core').GLShader; -let Const = require('./const'); +import {GLShader} from 'pixi-gl-core'; +import Const from './const'; -function checkPrecision(src) { - if (src instanceof Array) { - if (src[0].substring(0,9) !== 'precision') { +function checkPrecision(src) +{ + if (src instanceof Array) + { + if (src[0].substring(0,9) !== 'precision') + { let copy = src.slice(0); copy.unshift('precision ' + Const.PRECISION.DEFAULT + ' float;'); return copy; } - } else { - if (src.substring(0,9) !== 'precision') { + } + else + { + if (src.substring(0,9) !== 'precision') + { return 'precision ' + Const.PRECISION.DEFAULT + ' float;\n' + src; } } @@ -26,10 +32,12 @@ * @param vertexSrc {string|string[]} The vertex shader source as an array of strings. * @param fragmentSrc {string|string[]} The fragment shader source as an array of strings. */ -class Shader extends GLShader { - constructor(gl, vertexSrc, fragmentSrc) { +class Shader extends GLShader +{ + constructor(gl, vertexSrc, fragmentSrc) + { super(gl, checkPrecision(vertexSrc), checkPrecision(fragmentSrc)); } } -module.exports = Shader; +export default Shader; \ No newline at end of file diff --git a/src/core/const.js b/src/core/const.js index 27b0bee..4d4e9bf 100644 --- a/src/core/const.js +++ b/src/core/const.js @@ -1,10 +1,11 @@ +import maxRecommendedTextures from './utils/maxRecommendedTextures'; /** * Constant values used in pixi * * @lends PIXI */ -let CONST = { +const CONST = { /** * String of the current PIXI version. * @@ -362,7 +363,7 @@ * @constant * @type {number} */ - SPRITE_MAX_TEXTURES: require('./utils/maxRecommendedTextures')(32) + SPRITE_MAX_TEXTURES: maxRecommendedTextures(32) }; -module.exports = CONST; +export default CONST; diff --git a/src/core/display/Bounds.js b/src/core/display/Bounds.js index a8e442d..e16c135 100644 --- a/src/core/display/Bounds.js +++ b/src/core/display/Bounds.js @@ -1,5 +1,5 @@ -let math = require('../math'), - Rectangle = math.Rectangle; +import math from '../math'; +const Rectangle = math.Rectangle; /** * 'Builder' pattern for bounds rectangles @@ -9,7 +9,8 @@ * @class * @memberof PIXI */ -class Bounds { +class Bounds +{ constructor() { /** @@ -221,4 +222,4 @@ } } -module.exports = Bounds; +export default Bounds; \ No newline at end of file diff --git a/src/core/display/Container.js b/src/core/display/Container.js index d7e6a1d..47870b7 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -1,5 +1,5 @@ -let utils = require('../utils'), - DisplayObject = require('./DisplayObject'); +import utils from '../utils'; +import DisplayObject from './DisplayObject'; /** * A Container represents a collection of display objects. @@ -13,7 +13,8 @@ * @extends PIXI.DisplayObject * @memberof PIXI */ -class Container extends DisplayObject { +class Container extends DisplayObject +{ constructor() { super(); @@ -519,40 +520,33 @@ } } -} - -module.exports = Container; - -Object.defineProperties(Container.prototype, { /** * The width of the Container, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Container# */ - width: { - get: function () + get width() + { + return this.scale.x * this.getLocalBounds().width; + } + set width(value) + { + + let width = this.getLocalBounds().width; + + if (width !== 0) { - return this.scale.x * this.getLocalBounds().width; - }, - set: function (value) - { - - let width = this.getLocalBounds().width; - - if (width !== 0) - { - this.scale.x = value / width; - } - else - { - this.scale.x = 1; - } - - - this._width = value; + this.scale.x = value / width; } - }, + else + { + this.scale.x = 1; + } + + + this._width = value; + } /** * The height of the Container, setting this will actually modify the scale to achieve the value set @@ -560,29 +554,29 @@ * @member {number} * @memberof PIXI.Container# */ - height: { - get: function () - { - return this.scale.y * this.getLocalBounds().height; - }, - set: function (value) - { - - let height = this.getLocalBounds().height; - - if (height !== 0) - { - this.scale.y = value / height ; - } - else - { - this.scale.y = 1; - } - - this._height = value; - } + get height() + { + return this.scale.y * this.getLocalBounds().height; } -}); + set height(value) + { + + let height = this.getLocalBounds().height; + + if (height !== 0) + { + this.scale.y = value / height ; + } + else + { + this.scale.y = 1; + } + + this._height = value; + } +} // performance increase to avoid using call.. (10x faster) Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; + +export default Container; diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index 401d42e..b7bc01b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -1,10 +1,10 @@ -let EventEmitter = require('eventemitter3'), - CONST = require('../const'), - TransformStatic = require('./TransformStatic'), - Transform = require('./Transform'), - Bounds = require('./Bounds'), - math = require('../math');//, - //_tempDisplayObjectParent = new DisplayObject(); +import EventEmitter from 'eventemitter3'; +import CONST from '../const'; +import TransformStatic from './TransformStatic'; +import Transform from './Transform'; +import Bounds from './Bounds'; +import math from '../math'; +//_tempDisplayObjectParent = new DisplayObject(); /** * The base class for all objects that are rendered on the screen. @@ -15,7 +15,8 @@ * @mixes PIXI.interaction.interactiveTarget * @memberof PIXI */ -class DisplayObject extends EventEmitter { +class DisplayObject extends EventEmitter +{ constructor() { super(); @@ -380,13 +381,6 @@ this.interactive = false; this.interactiveChildren = false; } - -} - -module.exports = DisplayObject; - - -Object.defineProperties(DisplayObject.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * An alias to position.x @@ -394,16 +388,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - x: { - get: function () - { - return this.position.x; - }, - set: function (value) - { - this.transform.position.x = value; - } - }, + get x() + { + return this.position.x; + } + set x(value) + { + this.transform.position.x = value; + } /** * The position of the displayObject on the y axis relative to the local coordinates of the parent. @@ -412,16 +404,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - y: { - get: function () - { - return this.position.y; - }, - set: function (value) - { - this.transform.position.y = value; - } - }, + get y() + { + return this.position.y; + } + set y(value) + { + this.transform.position.y = value; + } /** * Current transform of the object based on world (parent) factors @@ -430,12 +420,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldTransform: { - get: function () - { - return this.transform.worldTransform; - } - }, + get worldTransform() + { + return this.transform.worldTransform; + } /** * Current transform of the object based on local factors: position, scale, other stuff @@ -444,12 +432,10 @@ * @memberof PIXI.DisplayObject# * @readonly */ - localTransform: { - get: function () - { - return this.transform.localTransform; - } - }, + get localTransform() + { + return this.transform.localTransform; + } /** * The coordinate of the object relative to the local coordinates of the parent. @@ -458,15 +444,13 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - position: { - get: function() - { - return this.transform.position; - }, - set: function(value) { - this.transform.position.copy(value); - } - }, + get position() + { + return this.transform.position; + } + set position(value) { + this.transform.position.copy(value); + } /** * The scale factor of the object. @@ -475,14 +459,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - scale: { - get: function() { - return this.transform.scale; - }, - set: function(value) { - this.transform.scale.copy(value); - } - }, + get scale() { + return this.transform.scale; + } + set scale(value) { + this.transform.scale.copy(value); + } /** * The pivot point of the displayObject that it rotates around @@ -491,14 +473,12 @@ * @member {PIXI.Point|PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - pivot: { - get: function() { - return this.transform.pivot; - }, - set: function(value) { - this.transform.pivot.copy(value); - } - }, + get pivot() { + return this.transform.pivot; + } + set pivot(value) { + this.transform.pivot.copy(value); + } /** * The skew factor for the object in radians. @@ -507,14 +487,12 @@ * @member {PIXI.ObservablePoint} * @memberof PIXI.DisplayObject# */ - skew: { - get: function() { - return this.transform.skew; - }, - set: function(value) { - this.transform.skew.copy(value); - } - }, + get skew() { + return this.transform.skew; + } + set skew(value) { + this.transform.skew.copy(value); + } /** * The rotation of the object in radians. @@ -522,16 +500,14 @@ * @member {number} * @memberof PIXI.DisplayObject# */ - rotation: { - get: function () - { - return this.transform.rotation; - }, - set: function (value) - { - this.transform.rotation = value; - } - }, + get rotation() + { + return this.transform.rotation; + } + set rotation(value) + { + this.transform.rotation = value; + } /** * Indicates if the sprite is globally visible. @@ -540,24 +516,22 @@ * @memberof PIXI.DisplayObject# * @readonly */ - worldVisible: { - get: function () - { - let item = this; + get worldVisible() + { + let item = this; - do { - if (!item.visible) - { - return false; - } + do { + if (!item.visible) + { + return false; + } - item = item.parent; - } while (item); + item = item.parent; + } while (item); - return true; - } - }, - + return true; + } + /** * Sets a mask for the displayObject. A mask is an object that limits the visibility of an object to the shape of the mask applied to it. * In PIXI a regular mask must be a PIXI.Graphics or a PIXI.Sprite object. This allows for much faster masking in canvas as it utilises shape clipping. @@ -568,26 +542,24 @@ * @member {PIXI.Graphics|PIXI.Sprite} * @memberof PIXI.DisplayObject# */ - mask: { - get: function () + get mask() + { + return this._mask; + } + set mask(value) + { + if (this._mask) { - return this._mask; - }, - set: function (value) - { - if (this._mask) - { - this._mask.renderable = true; - } - - this._mask = value; - - if (this._mask) - { - this._mask.renderable = false; - } + this._mask.renderable = true; } - }, + + this._mask = value; + + if (this._mask) + { + this._mask.renderable = false; + } + } /** * Sets the filters for the displayObject. @@ -597,18 +569,17 @@ * @member {PIXI.AbstractFilter[]} * @memberof PIXI.DisplayObject# */ - filters: { - get: function () - { - return this._filters && this._filters.slice(); - }, - set: function (value) - { - this._filters = value && value.slice(); - } + get filters() + { + return this._filters && this._filters.slice(); } - -}); + set filters(value) + { + this._filters = value && value.slice(); + } +} // performance increase to avoid using call.. (10x faster) DisplayObject.prototype.displayObjectUpdateTransform = DisplayObject.prototype.updateTransform; + +export default DisplayObject; \ No newline at end of file diff --git a/src/core/display/Transform.js b/src/core/display/Transform.js index 9159bb6..9065289 100644 --- a/src/core/display/Transform.js +++ b/src/core/display/Transform.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** @@ -10,7 +10,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class Transform extends TransformBase { +class Transform extends TransformBase +{ constructor() { super(); @@ -130,25 +131,20 @@ matrix.decompose(this); } -} - -Object.defineProperties(Transform.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.Transform# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + } +} -module.exports = Transform; +export default Transform; \ No newline at end of file diff --git a/src/core/display/TransformBase.js b/src/core/display/TransformBase.js index f696b2f..52f66fb 100644 --- a/src/core/display/TransformBase.js +++ b/src/core/display/TransformBase.js @@ -1,4 +1,4 @@ -let math = require('../math'); +import math from '../math'; /** @@ -7,7 +7,8 @@ * @class * @memberof PIXI */ -class TransformBase { +class TransformBase +{ constructor() { /** @@ -66,4 +67,4 @@ TransformBase.IDENTITY = new TransformBase(); -module.exports = TransformBase; +export default TransformBase; \ No newline at end of file diff --git a/src/core/display/TransformStatic.js b/src/core/display/TransformStatic.js index d6486c9..c2d2fcc 100644 --- a/src/core/display/TransformStatic.js +++ b/src/core/display/TransformStatic.js @@ -1,5 +1,5 @@ -let math = require('../math'), - TransformBase = require('./TransformBase'); +import math from '../math'; +import TransformBase from './TransformBase'; /** * Transform that takes care about its versions @@ -8,7 +8,8 @@ * @extends PIXI.TransformBase * @memberof PIXI */ -class TransformStatic extends TransformBase { +class TransformStatic extends TransformBase +{ constructor() { super(); @@ -158,26 +159,21 @@ this._localID ++; } -} - -Object.defineProperties(TransformStatic.prototype, { /** * The rotation of the object in radians. * * @member {number} * @memberof PIXI.TransformStatic# */ - rotation: { - get: function () { - return this._rotation; - }, - set: function (value) { - this._rotation = value; - this._sr = Math.sin(value); - this._cr = Math.cos(value); - this._localID ++; - } + get rotation() { + return this._rotation; } -}); + set rotation(value) { + this._rotation = value; + this._sr = Math.sin(value); + this._cr = Math.cos(value); + this._localID ++; + } +} -module.exports = TransformStatic; +export default TransformStatic; \ No newline at end of file diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index 32463a4..f97368b 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -1,19 +1,20 @@ -let Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - Texture = require('../textures/Texture'), - GraphicsData = require('./GraphicsData'), - Sprite = require('../sprites/Sprite'), - math = require('../math'), - CONST = require('../const'), - utils = require('../utils'), - Bounds = require('../display/Bounds'), - bezierCurveTo = require('./utils/bezierCurveTo'), - CanvasRenderer = require('../renderers/canvas/CanvasRenderer'), - canvasRenderer, - tempMatrix = new math.Matrix(), - tempPoint = new math.Point(), - tempColor1 = new Float32Array(4), - tempColor2 = new Float32Array(4); +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import Texture from '../textures/Texture'; +import GraphicsData from './GraphicsData'; +import Sprite from '../sprites/Sprite'; +import math from '../math'; +import CONST from '../const'; +import utils from '../utils'; +import Bounds from '../display/Bounds'; +import bezierCurveTo from './utils/bezierCurveTo'; +import CanvasRenderer from '../renderers/canvas/CanvasRenderer'; + +let canvasRenderer; +const tempMatrix = new math.Matrix(); +const tempPoint = new math.Point(); +const tempColor1 = new Float32Array(4); +const tempColor2 = new Float32Array(4); /** * The Graphics class contains methods used to draw primitive shapes such as lines, circles and @@ -23,7 +24,8 @@ * @extends PIXI.Container * @memberof PIXI */ -class Graphics extends Container { +class Graphics extends Container +{ constructor() { super(); @@ -1051,4 +1053,4 @@ Graphics._SPRITE_TEXTURE = null; -module.exports = Graphics; +export default Graphics; \ No newline at end of file diff --git a/src/core/graphics/GraphicsData.js b/src/core/graphics/GraphicsData.js index b2a6b70..a1ff63e 100644 --- a/src/core/graphics/GraphicsData.js +++ b/src/core/graphics/GraphicsData.js @@ -11,7 +11,8 @@ * @param fill {boolean} whether or not the shape is filled with a colour * @param shape {PIXI.Circle|PIXI.Rectangle|PIXI.Ellipse|PIXI.Polygon} The shape object to draw. */ -class GraphicsData { +class GraphicsData +{ constructor(lineWidth, lineColor, lineAlpha, fillColor, fillAlpha, fill, shape) { /* @@ -103,4 +104,4 @@ } } -module.exports = GraphicsData; \ No newline at end of file +export default GraphicsData; \ No newline at end of file diff --git a/src/core/graphics/canvas/CanvasGraphicsRenderer.js b/src/core/graphics/canvas/CanvasGraphicsRenderer.js index b5785d2..3bd740a 100644 --- a/src/core/graphics/canvas/CanvasGraphicsRenderer.js +++ b/src/core/graphics/canvas/CanvasGraphicsRenderer.js @@ -1,5 +1,5 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; /** * @author Mat Groves @@ -21,7 +21,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.SystemRenderer} The current PIXI renderer. */ -class CanvasGraphicsRenderer { +class CanvasGraphicsRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -269,9 +270,8 @@ { this.renderer = null; } - } -module.exports = CanvasGraphicsRenderer; - CanvasRenderer.registerPlugin('graphics', CanvasGraphicsRenderer); + +export default CanvasGraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/utils/bezierCurveTo.js b/src/core/graphics/utils/bezierCurveTo.js index 2f18868..14b799e 100644 --- a/src/core/graphics/utils/bezierCurveTo.js +++ b/src/core/graphics/utils/bezierCurveTo.js @@ -16,7 +16,7 @@ * @param [path=number[]] Path array to push points into * @return {PIXI.Graphics} */ -let bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line +const bezierCurveTo = function (fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, path) // jshint ignore:line { path = path || []; @@ -49,4 +49,4 @@ return path; }; -module.exports = bezierCurveTo; +export default bezierCurveTo; diff --git a/src/core/graphics/webgl/GraphicsRenderer.js b/src/core/graphics/webgl/GraphicsRenderer.js index a4aacd7..5a65458 100644 --- a/src/core/graphics/webgl/GraphicsRenderer.js +++ b/src/core/graphics/webgl/GraphicsRenderer.js @@ -1,17 +1,14 @@ -let utils = require('../../utils'), - CONST = require('../../const'), - ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - WebGLGraphicsData = require('./WebGLGraphicsData'), - PrimitiveShader = require('./shaders/PrimitiveShader'), +import utils from '../../utils'; +import CONST from '../../const'; +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import WebGLGraphicsData from './WebGLGraphicsData'; +import PrimitiveShader from './shaders/PrimitiveShader'; - // some drawing functions.. - buildPoly = require('./utils/buildPoly'), - buildRectangle = require('./utils/buildRectangle'), - buildRoundedRectangle = require('./utils/buildRoundedRectangle'), - buildCircle = require('./utils/buildCircle'); - - +import buildPoly from './utils/buildPoly'; +import buildRectangle from './utils/buildRectangle'; +import buildRoundedRectangle from './utils/buildRoundedRectangle'; +import buildCircle from './utils/buildCircle'; /** * Renders the graphics object. @@ -21,7 +18,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class GraphicsRenderer extends ObjectRenderer { +class GraphicsRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -216,9 +214,8 @@ return webGLData; } - } -module.exports = GraphicsRenderer; - WebGLRenderer.registerPlugin('graphics', GraphicsRenderer); + +export default GraphicsRenderer; \ No newline at end of file diff --git a/src/core/graphics/webgl/WebGLGraphicsData.js b/src/core/graphics/webgl/WebGLGraphicsData.js index b228027..c6605f9 100644 --- a/src/core/graphics/webgl/WebGLGraphicsData.js +++ b/src/core/graphics/webgl/WebGLGraphicsData.js @@ -1,5 +1,4 @@ -let glCore = require('pixi-gl-core'); - +import glCore from 'pixi-gl-core'; /** * An object containing WebGL specific properties to be used by the WebGL renderer @@ -11,7 +10,8 @@ * @param shader {PIXI.Shader} The shader * @param attribsState {object} The state for the VAO */ -class WebGLGraphicsData { +class WebGLGraphicsData +{ constructor(gl, shader, attribsState) { @@ -119,7 +119,6 @@ this.glPoints = null; this.glIndices = null; } - } -module.exports = WebGLGraphicsData; +export default WebGLGraphicsData; \ No newline at end of file diff --git a/src/core/graphics/webgl/shaders/PrimitiveShader.js b/src/core/graphics/webgl/shaders/PrimitiveShader.js index 0119d3c..82f8b13 100644 --- a/src/core/graphics/webgl/shaders/PrimitiveShader.js +++ b/src/core/graphics/webgl/shaders/PrimitiveShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../../Shader'); +import Shader from '../../../Shader'; /** * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}. @@ -8,7 +8,8 @@ * @extends PIXI.Shader * @param gl {WebGLRenderingContext} The webgl shader manager this shader works for. */ -class PrimitiveShader extends Shader { +class PrimitiveShader extends Shader +{ constructor(gl) { super(gl, @@ -42,4 +43,4 @@ } } -module.exports = PrimitiveShader; +export default PrimitiveShader; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildCircle.js b/src/core/graphics/webgl/utils/buildCircle.js index 3e1251d..8cf774c 100644 --- a/src/core/graphics/webgl/utils/buildCircle.js +++ b/src/core/graphics/webgl/utils/buildCircle.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - CONST = require('../../../const'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import CONST from '../../../const'; +import utils from '../../../utils'; /** * Builds a circle to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object to draw * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildCircle = function (graphicsData, webGLData) +const buildCircle = function (graphicsData, webGLData) { // need to convert points to a nice regular data let circleData = graphicsData.shape; @@ -86,5 +86,4 @@ } }; - -module.exports = buildCircle; +export default buildCircle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildComplexPoly.js b/src/core/graphics/webgl/utils/buildComplexPoly.js index 8701929..68843eb 100644 --- a/src/core/graphics/webgl/utils/buildComplexPoly.js +++ b/src/core/graphics/webgl/utils/buildComplexPoly.js @@ -1,6 +1,4 @@ -let utils = require('../../../utils'); - - +import utils from '../../../utils'; /** * Builds a complex polygon to draw @@ -12,7 +10,7 @@ * @param graphicsData {PIXI.Graphics} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildComplexPoly = function (graphicsData, webGLData) +const buildComplexPoly = function (graphicsData, webGLData) { //TODO - no need to copy this as it gets turned into a FLoat32Array anyways.. let points = graphicsData.points.slice(); @@ -64,9 +62,6 @@ { indices.push( i ); } - }; - - -module.exports = buildComplexPoly; +export default buildComplexPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildLine.js b/src/core/graphics/webgl/utils/buildLine.js index 226e7da..9cebcec 100644 --- a/src/core/graphics/webgl/utils/buildLine.js +++ b/src/core/graphics/webgl/utils/buildLine.js @@ -1,5 +1,5 @@ -let math = require('../../../math'), - utils = require('../../../utils'); +import math from '../../../math'; +import utils from '../../../utils'; /** * Builds a line to draw @@ -11,7 +11,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildLine = function (graphicsData, webGLData) +const buildLine = function (graphicsData, webGLData) { // TODO OPTIMISE! let i = 0; @@ -219,4 +219,4 @@ indices.push(indexStart-1); }; -module.exports = buildLine; +export default buildLine; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildPoly.js b/src/core/graphics/webgl/utils/buildPoly.js index f965948..f23e6f4 100644 --- a/src/core/graphics/webgl/utils/buildPoly.js +++ b/src/core/graphics/webgl/utils/buildPoly.js @@ -1,6 +1,6 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'), - earcut = require('earcut'); +import buildLine from './buildLine'; +import utils from '../../../utils'; +import earcut from 'earcut'; /** * Builds a polygon to draw @@ -12,7 +12,7 @@ * @param graphicsData {PIXI.WebGLGraphicsData} The graphics object containing all the necessary properties * @param webGLData {object} an object containing all the webGL-specific information to create this shape */ -let buildPoly = function (graphicsData, webGLData) +const buildPoly = function (graphicsData, webGLData) { graphicsData.points = graphicsData.shape.points.slice(); @@ -75,5 +75,4 @@ } }; - -module.exports = buildPoly; +export default buildPoly; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRectangle.js b/src/core/graphics/webgl/utils/buildRectangle.js index addc615..b5f7929 100644 --- a/src/core/graphics/webgl/utils/buildRectangle.js +++ b/src/core/graphics/webgl/utils/buildRectangle.js @@ -1,5 +1,5 @@ -let buildLine = require('./buildLine'), - utils = require('../../../utils'); +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rectangle to draw @@ -70,4 +70,4 @@ } }; -module.exports = buildRectangle; +export default buildRectangle; \ No newline at end of file diff --git a/src/core/graphics/webgl/utils/buildRoundedRectangle.js b/src/core/graphics/webgl/utils/buildRoundedRectangle.js index f5667ac..52b0053 100644 --- a/src/core/graphics/webgl/utils/buildRoundedRectangle.js +++ b/src/core/graphics/webgl/utils/buildRoundedRectangle.js @@ -1,6 +1,6 @@ -let earcut = require('earcut'), - buildLine = require('./buildLine'), - utils = require('../../../utils'); +import earcut from 'earcut'; +import buildLine from './buildLine'; +import utils from '../../../utils'; /** * Builds a rounded rectangle to draw @@ -130,5 +130,4 @@ return points; }; - -module.exports = buildRoundedRectangle; +export default buildRoundedRectangle; \ No newline at end of file diff --git a/src/core/index.js b/src/core/index.js index 0004416..122a2f3 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -1,66 +1,96 @@ -/** - * @file Main export of the PIXI core library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import consts from './const'; +import math from './math'; +import utils from './utils'; +import ticker from './ticker'; +import DisplayObject from './display/DisplayObject'; +import Container from './display/Container'; +import Transform from './display/Transform'; +import TransformStatic from './display/TransformStatic'; +import TransformBase from './display/TransformBase'; +import Sprite from './sprites/Sprite'; +import CanvasSpriteRenderer from './sprites/canvas/CanvasSpriteRenderer'; +import CanvasTinter from './sprites/canvas/CanvasTinter'; +import SpriteRenderer from './sprites/webgl/SpriteRenderer'; +import Text from './text/Text'; +import TextStyle from './text/TextStyle'; +import Graphics from './graphics/Graphics'; +import GraphicsData from './graphics/GraphicsData'; +import GraphicsRenderer from './graphics/webgl/GraphicsRenderer'; +import CanvasGraphicsRenderer from './graphics/canvas/CanvasGraphicsRenderer'; +import Texture from './textures/Texture'; +import BaseTexture from './textures/BaseTexture'; +import RenderTexture from './textures/RenderTexture'; +import BaseRenderTexture from './textures/BaseRenderTexture'; +import VideoBaseTexture from './textures/VideoBaseTexture'; +import TextureUvs from './textures/TextureUvs'; +import CanvasRenderer from './renderers/canvas/CanvasRenderer'; +import CanvasRenderTarget from './renderers/canvas/utils/CanvasRenderTarget'; +import Shader from './Shader'; +import WebGLRenderer from './renderers/webgl/WebGLRenderer'; +import WebGLManager from './renderers/webgl/managers/WebGLManager'; +import ObjectRenderer from './renderers/webgl/utils/ObjectRenderer'; +import RenderTarget from './renderers/webgl/utils/RenderTarget'; +import Quad from './renderers/webgl/utils/Quad'; +import SpriteMaskFilter from './renderers/webgl/filters/spriteMask/SpriteMaskFilter'; +import Filter from './renderers/webgl/filters/Filter'; +import glCore from 'pixi-gl-core'; /** * @namespace PIXI */ // export core and const. We assign core to const so that the non-reference types in const remain in-tact -let core = module.exports = Object.assign(require('./const'), require('./math'), { +const core = Object.assign(consts, math, { // utils - utils: require('./utils'), - ticker: require('./ticker'), + utils, + ticker, // display - DisplayObject: require('./display/DisplayObject'), - Container: require('./display/Container'), - Transform: require('./display/Transform'), - TransformStatic: require('./display/TransformStatic'), - TransformBase: require('./display/TransformBase'), + DisplayObject, + Container, + Transform, + TransformStatic, + TransformBase, // sprites - Sprite: require('./sprites/Sprite'), - CanvasSpriteRenderer: require('./sprites/canvas/CanvasSpriteRenderer'), - CanvasTinter: require('./sprites/canvas/CanvasTinter'), - SpriteRenderer: require('./sprites/webgl/SpriteRenderer'), + Sprite, + CanvasSpriteRenderer, + CanvasTinter, + SpriteRenderer, // text - Text: require('./text/Text'), - TextStyle: require('./text/TextStyle'), + Text, + TextStyle, // primitives - Graphics: require('./graphics/Graphics'), - GraphicsData: require('./graphics/GraphicsData'), - GraphicsRenderer: require('./graphics/webgl/GraphicsRenderer'), - CanvasGraphicsRenderer: require('./graphics/canvas/CanvasGraphicsRenderer'), + Graphics, + GraphicsData, + GraphicsRenderer, + CanvasGraphicsRenderer, // textures - Texture: require('./textures/Texture'), - BaseTexture: require('./textures/BaseTexture'), - RenderTexture: require('./textures/RenderTexture'), - BaseRenderTexture: require('./textures/BaseRenderTexture'), - VideoBaseTexture: require('./textures/VideoBaseTexture'), - TextureUvs: require('./textures/TextureUvs'), + Texture, + BaseTexture, + RenderTexture, + BaseRenderTexture, + VideoBaseTexture, + TextureUvs, // renderers - canvas - CanvasRenderer: require('./renderers/canvas/CanvasRenderer'), - CanvasRenderTarget: require('./renderers/canvas/utils/CanvasRenderTarget'), + CanvasRenderer, + CanvasRenderTarget, // renderers - webgl - Shader: require('./Shader'), - WebGLRenderer: require('./renderers/webgl/WebGLRenderer'), - WebGLManager: require('./renderers/webgl/managers/WebGLManager'), - ObjectRenderer: require('./renderers/webgl/utils/ObjectRenderer'), - RenderTarget: require('./renderers/webgl/utils/RenderTarget'), - Quad: require('./renderers/webgl/utils/Quad'), + Shader, + WebGLRenderer, + WebGLManager, + ObjectRenderer, + RenderTarget, + Quad, // filters - webgl - SpriteMaskFilter: require('./renderers/webgl/filters/spriteMask/SpriteMaskFilter'), - Filter: require('./renderers/webgl/filters/Filter'), + SpriteMaskFilter, + Filter, - glCore: require('pixi-gl-core'), + glCore, /** * This helper function will automatically detect which renderer you should be using. @@ -94,3 +124,5 @@ return new core.CanvasRenderer(width, height, options); } }); + +export default core; \ No newline at end of file diff --git a/src/core/math/GroupD8.js b/src/core/math/GroupD8.js index f79c217..1cf7336 100644 --- a/src/core/math/GroupD8.js +++ b/src/core/math/GroupD8.js @@ -1,11 +1,11 @@ // Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group of order 16 +import Matrix from './Matrix'; let ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1]; let uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1]; let vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1]; let vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1]; let tempMatrices = []; -let Matrix = require('./Matrix'); let mul = []; @@ -58,7 +58,7 @@ * * @namespace PIXI.GroupD8 */ -let GroupD8 = { +const GroupD8 = { E: 0, SE: 1, S: 2, @@ -159,4 +159,4 @@ } }; -module.exports = GroupD8; +export default GroupD8; \ No newline at end of file diff --git a/src/core/math/Matrix.js b/src/core/math/Matrix.js index 60d5e02..0a6013a 100644 --- a/src/core/math/Matrix.js +++ b/src/core/math/Matrix.js @@ -2,7 +2,7 @@ // should either fix it or change the jshint config // jshint -W072 -let Point = require('./Point'); +import Point from './Point'; /** * The pixi Matrix class as an object, which makes it a lot faster, @@ -14,7 +14,8 @@ * @class * @memberof PIXI */ -class Matrix { +class Matrix +{ constructor() { /** @@ -490,4 +491,4 @@ } } -module.exports = Matrix; \ No newline at end of file +export default Matrix; \ No newline at end of file diff --git a/src/core/math/ObservablePoint.js b/src/core/math/ObservablePoint.js index 3999186..c19660e 100644 --- a/src/core/math/ObservablePoint.js +++ b/src/core/math/ObservablePoint.js @@ -10,7 +10,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class ObservablePoint { +class ObservablePoint +{ constructor(cb, scope, x, y) { this._x = x || 0; @@ -53,48 +54,42 @@ this.cb.call(this.scope); } } -} -module.exports = ObservablePoint; - - -Object.defineProperties(ObservablePoint.prototype, { /** * The position of the displayObject on the x axis relative to the local coordinates of the parent. * * @member {number} * @memberof PIXI.ObservablePoint# */ - x: { - get: function () - { - return this._x; - }, - set: function (value) - { - if (this._x !== value) { - this._x = value; - this.cb.call(this.scope); - } - } - }, - /** - * The position of the displayObject on the x axis relative to the local coordinates of the parent. - * - * @member {number} - * @memberof PIXI.ObservablePoint# - */ - y: { - get: function () - { - return this._y; - }, - set: function (value) - { - if (this._y !== value) { - this._y = value; - this.cb.call(this.scope); - } + get x() + { + return this._x; + } + set x(value) + { + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); } } -}); + + /** + * The position of the displayObject on the x axis relative to the local coordinates of the parent. + * + * @member {number} + * @memberof PIXI.ObservablePoint# + */ + get y() + { + return this._y; + } + set y(value) + { + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } + } +} + +export default ObservablePoint; \ No newline at end of file diff --git a/src/core/math/Point.js b/src/core/math/Point.js index dc5c36d..3a392d0 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -7,7 +7,8 @@ * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ -class Point { +class Point +{ constructor(x, y) { /** @@ -67,4 +68,4 @@ } -module.exports = Point; +export default Point; \ No newline at end of file diff --git a/src/core/math/index.js b/src/core/math/index.js index 8f199d0..709865a 100644 --- a/src/core/math/index.js +++ b/src/core/math/index.js @@ -1,22 +1,33 @@ +import Point from './Point'; +import ObservablePoint from './ObservablePoint'; +import Matrix from './Matrix'; +import GroupD8 from './GroupD8'; + +import Circle from './shapes/Circle'; +import Ellipse from './shapes/Ellipse'; +import Polygon from './shapes/Polygon'; +import Rectangle from './shapes/Rectangle'; +import RoundedRectangle from './shapes/RoundedRectangle'; + /** * Math classes and utilities mixed into PIXI namespace. * * @lends PIXI */ -module.exports = { +export default { // These will be mixed to be made publicly available, // while this module is used internally in core // to avoid circular dependencies and cut down on // internal module requires. - Point: require('./Point'), - ObservablePoint: require('./ObservablePoint'), - Matrix: require('./Matrix'), - GroupD8: require('./GroupD8'), + Point, + ObservablePoint, + Matrix, + GroupD8, - Circle: require('./shapes/Circle'), - Ellipse: require('./shapes/Ellipse'), - Polygon: require('./shapes/Polygon'), - Rectangle: require('./shapes/Rectangle'), - RoundedRectangle: require('./shapes/RoundedRectangle') + Circle, + Ellipse, + Polygon, + Rectangle, + RoundedRectangle }; diff --git a/src/core/math/shapes/Circle.js b/src/core/math/shapes/Circle.js index cae0591..c7baaf0 100644 --- a/src/core/math/shapes/Circle.js +++ b/src/core/math/shapes/Circle.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Circle object can be used to specify a hit area for displayObjects @@ -10,7 +10,8 @@ * @param y {number} The Y coordinate of the center of this circle * @param radius {number} The radius of the circle */ -class Circle { +class Circle +{ constructor(x, y, radius) { /** @@ -85,7 +86,6 @@ { return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2); } - } -module.exports = Circle; +export default Circle; \ No newline at end of file diff --git a/src/core/math/shapes/Ellipse.js b/src/core/math/shapes/Ellipse.js index 54bddaa..b1d9fa4 100644 --- a/src/core/math/shapes/Ellipse.js +++ b/src/core/math/shapes/Ellipse.js @@ -1,5 +1,5 @@ -let Rectangle = require('./Rectangle'), - CONST = require('../../const'); +import Rectangle from './Rectangle'; +import CONST from '../../const'; /** * The Ellipse object can be used to specify a hit area for displayObjects @@ -11,7 +11,8 @@ * @param width {number} The half width of this ellipse * @param height {number} The half height of this ellipse */ -class Ellipse { +class Ellipse +{ constructor(x, y, width, height) { /** @@ -94,4 +95,4 @@ } } -module.exports = Ellipse; +export default Ellipse; \ No newline at end of file diff --git a/src/core/math/shapes/Polygon.js b/src/core/math/shapes/Polygon.js index 60b7fd0..6b376b3 100644 --- a/src/core/math/shapes/Polygon.js +++ b/src/core/math/shapes/Polygon.js @@ -1,5 +1,5 @@ -let Point = require('../Point'), - CONST = require('../../const'); +import Point from '../Point'; +import CONST from '../../const'; /** * @class @@ -10,7 +10,8 @@ * arguments passed can be flat x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are * Numbers. */ -class Polygon { +class Polygon +{ constructor(points_) { // prevents an argument assignment deopt @@ -113,7 +114,6 @@ return inside; } - } -module.exports = Polygon; +export default Polygon; \ No newline at end of file diff --git a/src/core/math/shapes/Rectangle.js b/src/core/math/shapes/Rectangle.js index af39d43..fe9c230 100644 --- a/src/core/math/shapes/Rectangle.js +++ b/src/core/math/shapes/Rectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * the Rectangle object is an area defined by its position, as indicated by its top-left corner point (x, y) and by its width and its height. @@ -10,7 +10,8 @@ * @param width {number} The overall width of this rectangle * @param height {number} The overall height of this rectangle */ -class Rectangle { +class Rectangle +{ constructor(x, y, width, height) { /** @@ -170,7 +171,6 @@ this.y = y1; this.height = y2 - y1; } - } -module.exports = Rectangle; +export default Rectangle; \ No newline at end of file diff --git a/src/core/math/shapes/RoundedRectangle.js b/src/core/math/shapes/RoundedRectangle.js index 04f784a..043ea2c 100644 --- a/src/core/math/shapes/RoundedRectangle.js +++ b/src/core/math/shapes/RoundedRectangle.js @@ -1,4 +1,4 @@ -let CONST = require('../../const'); +import CONST from '../../const'; /** * The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height and its radius. @@ -11,7 +11,8 @@ * @param height {number} The overall height of this rounded rectangle * @param radius {number} Controls the radius of the rounded corners */ -class RoundedRectangle { +class RoundedRectangle +{ constructor(x, y, width, height, radius) { /** @@ -89,7 +90,6 @@ return false; } - } -module.exports = RoundedRectangle; +export default RoundedRectangle; \ No newline at end of file diff --git a/src/core/renderers/SystemRenderer.js b/src/core/renderers/SystemRenderer.js index 880b6fb..acbfa3a 100644 --- a/src/core/renderers/SystemRenderer.js +++ b/src/core/renderers/SystemRenderer.js @@ -1,10 +1,12 @@ -let utils = require('../utils'), - math = require('../math'), - CONST = require('../const'), - Container = require('../display/Container'), - RenderTexture = require('../textures/RenderTexture'), - EventEmitter = require('eventemitter3'), - tempMatrix = new math.Matrix(); +import utils from '../utils'; +import math from '../math'; +import CONST from '../const'; +import Container from '../display/Container'; +import RenderTexture from '../textures/RenderTexture'; +import EventEmitter from 'eventemitter3'; + +const tempMatrix = new math.Matrix(); + /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. * Don't forget to add the CanvasRenderer.view to your DOM or you will not see anything :) @@ -25,7 +27,8 @@ * @param [options.backgroundColor=0x000000] {number} The background color of the rendered area (shown if not transparent). * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class SystemRenderer extends EventEmitter { +class SystemRenderer extends EventEmitter +{ constructor(system, width, height, options) { super(); @@ -261,28 +264,22 @@ this._lastObjectRendered = null; } -} - -module.exports = SystemRenderer; - -Object.defineProperties(SystemRenderer.prototype, { /** * The background color to fill if not transparent * * @member {number} * @memberof PIXI.SystemRenderer# */ - backgroundColor: + get backgroundColor() { - get: function () - { - return this._backgroundColor; - }, - set: function (val) - { - this._backgroundColor = val; - this._backgroundColorString = utils.hex2string(val); - utils.hex2rgb(val, this._backgroundColorRgba); - } + return this._backgroundColor; } -}); + set backgroundColor(val) + { + this._backgroundColor = val; + this._backgroundColorString = utils.hex2string(val); + utils.hex2rgb(val, this._backgroundColorRgba); + } +} + +export default SystemRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/CanvasRenderer.js b/src/core/renderers/canvas/CanvasRenderer.js index 21023a6..43e9bc0 100644 --- a/src/core/renderers/canvas/CanvasRenderer.js +++ b/src/core/renderers/canvas/CanvasRenderer.js @@ -1,9 +1,9 @@ -let SystemRenderer = require('../SystemRenderer'), - CanvasMaskManager = require('./utils/CanvasMaskManager'), - CanvasRenderTarget = require('./utils/CanvasRenderTarget'), - mapCanvasBlendModesToPixi = require('./utils/mapCanvasBlendModesToPixi'), - utils = require('../../utils'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import CanvasMaskManager from './utils/CanvasMaskManager'; +import CanvasRenderTarget from './utils/CanvasRenderTarget'; +import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; +import utils from '../../utils'; +import CONST from '../../const'; /** * The CanvasRenderer draws the scene and all its content onto a 2d canvas. This renderer should be used for browsers that do not support webGL. @@ -24,7 +24,8 @@ * not before the new render pass. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class CanvasRenderer extends SystemRenderer { +class CanvasRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -253,10 +254,9 @@ { this.rootContext[this.smoothProperty] = (CONST.SCALE_MODES.DEFAULT === CONST.SCALE_MODES.LINEAR); } - } - } -module.exports = CanvasRenderer; utils.pluginTarget.mixin(CanvasRenderer); + +export default CanvasRenderer; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasMaskManager.js b/src/core/renderers/canvas/utils/CanvasMaskManager.js index adc2a65..c0101ae 100644 --- a/src/core/renderers/canvas/utils/CanvasMaskManager.js +++ b/src/core/renderers/canvas/utils/CanvasMaskManager.js @@ -1,11 +1,13 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; + /** * A set of functions used to handle masking. * * @class * @memberof PIXI */ -class CanvasMaskManager { +class CanvasMaskManager +{ constructor(renderer) { this.renderer = renderer; @@ -156,7 +158,6 @@ } destroy() {} - } -module.exports = CanvasMaskManager; +export default CanvasMaskManager; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/CanvasRenderTarget.js b/src/core/renderers/canvas/utils/CanvasRenderTarget.js index c05127d..582b6e9 100644 --- a/src/core/renderers/canvas/utils/CanvasRenderTarget.js +++ b/src/core/renderers/canvas/utils/CanvasRenderTarget.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Creates a Canvas element of the given size. @@ -9,7 +9,8 @@ * @param height {number} the height for the newly created canvas * @param [resolution=1] The resolution / device pixel ratio of the canvas */ -class CanvasRenderTarget { +class CanvasRenderTarget +{ constructor(width, height, resolution) { /** @@ -65,41 +66,35 @@ this.canvas = null; } -} - -module.exports = CanvasRenderTarget; - -Object.defineProperties(CanvasRenderTarget.prototype, { /** * The width of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - width: { - get: function () - { - return this.canvas.width; - }, - set: function (val) - { - this.canvas.width = val; - } - }, + get width() + { + return this.canvas.width; + } + set width(val) + { + this.canvas.width = val; + } + /** * The height of the canvas buffer in pixels. * * @member {number} * @memberof PIXI.CanvasRenderTarget# */ - height: { - get: function () - { - return this.canvas.height; - }, - set: function (val) - { - this.canvas.height = val; - } + get height() + { + return this.canvas.height; } -}); + set height(val) + { + this.canvas.height = val; + } +} + +export default CanvasRenderTarget; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js index 2ffdba9..8ceeb88 100644 --- a/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js +++ b/src/core/renderers/canvas/utils/canUseNewCanvasBlendModes.js @@ -4,7 +4,7 @@ * Creates a little colored canvas * @return {canvas} a small canvas element */ -let createColoredCanvas = function(color) +const createColoredCanvas = function(color) { let canvas = document.createElement('canvas'); canvas.width = 6; @@ -22,7 +22,7 @@ * * @return {boolean} whether they are supported */ -let canUseNewCanvasBlendModes = function () +const canUseNewCanvasBlendModes = function () { if (typeof document === 'undefined') { @@ -53,5 +53,4 @@ return (data[0] === 255 && data[1] === 0 && data[2] === 0); }; - -module.exports = canUseNewCanvasBlendModes; +export default canUseNewCanvasBlendModes; \ No newline at end of file diff --git a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js index ba18847..88c2c01 100644 --- a/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js +++ b/src/core/renderers/canvas/utils/mapCanvasBlendModesToPixi.js @@ -1,5 +1,5 @@ -let CONST = require('../../../const'), -canUseNewCanvasBlendModes = require('./canUseNewCanvasBlendModes'); +import CONST from '../../../const'; +import canUseNewCanvasBlendModes from './canUseNewCanvasBlendModes'; /** * Maps blend combinations to Canvas @@ -56,4 +56,4 @@ return array; } -module.exports = mapCanvasBlendModesToPixi; +export default mapCanvasBlendModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureGarbageCollector.js b/src/core/renderers/webgl/TextureGarbageCollector.js index 2a8154a..94bcc93 100644 --- a/src/core/renderers/webgl/TextureGarbageCollector.js +++ b/src/core/renderers/webgl/TextureGarbageCollector.js @@ -1,5 +1,4 @@ - -let CONST = require('../../const'); +import CONST from '../../const'; /** * TextureGarbageCollector. This class manages the GPU and ensures that it does not get clogged up with textures that are no longer being used. @@ -8,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class TextureGarbageCollector { +class TextureGarbageCollector +{ constructor(renderer) { this.renderer = renderer; @@ -105,7 +105,6 @@ } } - } -module.exports = TextureGarbageCollector; +export default TextureGarbageCollector; \ No newline at end of file diff --git a/src/core/renderers/webgl/TextureManager.js b/src/core/renderers/webgl/TextureManager.js index a08f3b6..fa9af9d 100644 --- a/src/core/renderers/webgl/TextureManager.js +++ b/src/core/renderers/webgl/TextureManager.js @@ -1,7 +1,7 @@ -let GLTexture = require('pixi-gl-core').GLTexture, - CONST = require('../../const'), - RenderTarget = require('./utils/RenderTarget'), - utils = require('../../utils'); +import {GLTexture} from 'pixi-gl-core'; +import CONST from '../../const'; +import RenderTarget from './utils/RenderTarget'; +import utils from '../../utils'; /** * Helper class to create a webGL Texture @@ -10,7 +10,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class TextureManager { +class TextureManager +{ constructor(renderer) { /** @@ -202,7 +203,6 @@ this._managedTextures = null; } - } -module.exports = TextureManager; +export default TextureManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLRenderer.js b/src/core/renderers/webgl/WebGLRenderer.js index 22ef029..a88f8aa 100644 --- a/src/core/renderers/webgl/WebGLRenderer.js +++ b/src/core/renderers/webgl/WebGLRenderer.js @@ -1,18 +1,18 @@ -let SystemRenderer = require('../SystemRenderer'), - MaskManager = require('./managers/MaskManager'), - StencilManager = require('./managers/StencilManager'), - FilterManager = require('./managers/FilterManager'), - RenderTarget = require('./utils/RenderTarget'), - ObjectRenderer = require('./utils/ObjectRenderer'), - TextureManager = require('./TextureManager'), - TextureGarbageCollector = require('./TextureGarbageCollector'), - WebGLState = require('./WebGLState'), - createContext = require('pixi-gl-core').createContext, - mapWebGLDrawModesToPixi = require('./utils/mapWebGLDrawModesToPixi'), - validateContext = require('./utils/validateContext'), - utils = require('../../utils'), - glCore = require('pixi-gl-core'), - CONST = require('../../const'); +import SystemRenderer from '../SystemRenderer'; +import MaskManager from './managers/MaskManager'; +import StencilManager from './managers/StencilManager'; +import FilterManager from './managers/FilterManager'; +import RenderTarget from './utils/RenderTarget'; +import ObjectRenderer from './utils/ObjectRenderer'; +import TextureManager from './TextureManager'; +import TextureGarbageCollector from './TextureGarbageCollector'; +import WebGLState from './WebGLState'; +import {createContext} from 'pixi-gl-core'; +import mapWebGLDrawModesToPixi from './utils/mapWebGLDrawModesToPixi'; +import validateContext from './utils/validateContext'; +import utils from '../../utils'; +import glCore from 'pixi-gl-core'; +import CONST from '../../const'; let CONTEXT_UID = 0; @@ -40,7 +40,8 @@ * you need to call toDataUrl on the webgl context. * @param [options.roundPixels=false] {boolean} If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. */ -class WebGLRenderer extends SystemRenderer { +class WebGLRenderer extends SystemRenderer +{ constructor(width, height, options) { options = options || {}; @@ -554,8 +555,8 @@ // this = null; } - } -module.exports = WebGLRenderer; utils.pluginTarget.mixin(WebGLRenderer); + +export default WebGLRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/WebGLState.js b/src/core/renderers/webgl/WebGLState.js index 3ff5ea7..beffc3b 100755 --- a/src/core/renderers/webgl/WebGLState.js +++ b/src/core/renderers/webgl/WebGLState.js @@ -1,4 +1,4 @@ -let mapWebGLBlendModesToPixi = require('./utils/mapWebGLBlendModesToPixi'); +import mapWebGLBlendModesToPixi from './utils/mapWebGLBlendModesToPixi'; let BLEND = 0, DEPTH_TEST = 1, @@ -13,7 +13,8 @@ * @class * @param gl {WebGLRenderingContext} The current WebGL rendering context */ -class WebGLState { +class WebGLState +{ constructor(gl) { /** @@ -278,7 +279,6 @@ this.setState(this.defaultState); } - } -module.exports = WebGLState; +export default WebGLState; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/Filter.js b/src/core/renderers/webgl/filters/Filter.js index 9194dc8..1fba28e 100644 --- a/src/core/renderers/webgl/filters/Filter.js +++ b/src/core/renderers/webgl/filters/Filter.js @@ -1,7 +1,8 @@ -let extractUniformsFromSrc = require('./extractUniformsFromSrc'), - utils = require('../../../utils'), - CONST = require('../../../const'), - SOURCE_KEY_MAP = {}; +import extractUniformsFromSrc from './extractUniformsFromSrc'; +import utils from '../../../utils'; +import CONST from '../../../const'; + +const SOURCE_KEY_MAP = {}; // let math = require('../../../math'); /** @@ -12,7 +13,8 @@ * @param [uniforms] {object} Custom uniforms to use to augment the built-in ones. * @param [fragmentSrc] {string} The source of the fragment shader. */ -class Filter { +class Filter +{ constructor(vertexSrc, fragmentSrc, uniforms) { @@ -147,4 +149,4 @@ } -module.exports = Filter; +export default Filter; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js index 206bb5f..471b2aa 100644 --- a/src/core/renderers/webgl/filters/extractUniformsFromSrc.js +++ b/src/core/renderers/webgl/filters/extractUniformsFromSrc.js @@ -1,4 +1,6 @@ -let defaultValue = require('pixi-gl-core').shader.defaultValue; +import glCore from 'pixi-gl-core'; + +let defaultValue = glCore.shader.defaultValue; function extractUniformsFromSrc(vertexSrc, fragmentSrc, mask) { @@ -57,4 +59,4 @@ return uniforms; } -module.exports = extractUniformsFromSrc; +export default extractUniformsFromSrc; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/filterTransforms.js b/src/core/renderers/webgl/filters/filterTransforms.js index 2858d96..941d1ed 100644 --- a/src/core/renderers/webgl/filters/filterTransforms.js +++ b/src/core/renderers/webgl/filters/filterTransforms.js @@ -1,4 +1,4 @@ -let math = require('../../../math'); +import math from '../../../math'; /* * Calculates the mapped matrix @@ -8,7 +8,7 @@ */ // TODO playing around here.. this is temporary - (will end up in the shader) // thia returns a matrix that will normalise map filter cords in the filter to screen space -let calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { //let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), // let texture = {width:1136, height:700};//sprite._texture.baseTexture; @@ -24,7 +24,7 @@ }; -let calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) +const calculateNormalizedScreenSpaceMatrix = function (outputMatrix, filterArea, textureSize) { let mappedMatrix = outputMatrix.identity(); @@ -39,7 +39,7 @@ }; // this will map the filter coord so that a texture can be used based on the transform of a sprite -let calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) +const calculateSpriteMatrix = function (outputMatrix, filterArea, textureSize, sprite) { let worldTransform = sprite.worldTransform.copy(math.Matrix.TEMP_MATRIX), texture = sprite._texture.baseTexture; @@ -76,8 +76,8 @@ return mappedMatrix; }; -module.exports = { - calculateScreenSpaceMatrix:calculateScreenSpaceMatrix, - calculateNormalizedScreenSpaceMatrix:calculateNormalizedScreenSpaceMatrix, - calculateSpriteMatrix:calculateSpriteMatrix -}; +export default { + calculateScreenSpaceMatrix, + calculateNormalizedScreenSpaceMatrix, + calculateSpriteMatrix +}; \ No newline at end of file diff --git a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js index 69cc462..b2c5f8a 100644 --- a/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js +++ b/src/core/renderers/webgl/filters/spriteMask/SpriteMaskFilter.js @@ -1,8 +1,9 @@ -let Filter = require('../Filter'), - math = require('../../../../math'); +import Filter from '../Filter'; +import math from '../../../../math'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); + /** * The SpriteMaskFilter class * @@ -11,7 +12,8 @@ * @memberof PIXI * @param sprite {PIXI.Sprite} the target sprite */ -class SpriteMaskFilter extends Filter { +class SpriteMaskFilter extends Filter +{ constructor(sprite) { let maskMatrix = new math.Matrix(); @@ -44,7 +46,6 @@ filterManager.applyFilter(this, input, output); } - } -module.exports = SpriteMaskFilter; +export default SpriteMaskFilter; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/BlendModeManager.js b/src/core/renderers/webgl/managers/BlendModeManager.js index 3aea288..108ea68 100644 --- a/src/core/renderers/webgl/managers/BlendModeManager.js +++ b/src/core/renderers/webgl/managers/BlendModeManager.js @@ -1,4 +1,4 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class @@ -6,7 +6,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class BlendModeManager extends WebGLManager { +class BlendModeManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -37,7 +38,6 @@ return true; } - } -module.exports = BlendModeManager; +export default BlendModeManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/FilterManager.js b/src/core/renderers/webgl/managers/FilterManager.js index c951986..b019583 100644 --- a/src/core/renderers/webgl/managers/FilterManager.js +++ b/src/core/renderers/webgl/managers/FilterManager.js @@ -1,13 +1,13 @@ +import WebGLManager from './WebGLManager'; +import RenderTarget from '../utils/RenderTarget'; +import Quad from '../utils/Quad'; +import math from '../../../math'; +import Shader from '../../../Shader'; +import filterTransforms from '../filters/filterTransforms'; +import bitTwiddle from 'bit-twiddle'; -let WebGLManager = require('./WebGLManager'), - RenderTarget = require('../utils/RenderTarget'), - Quad = require('../utils/Quad'), - math = require('../../../math'), - Shader = require('../../../Shader'), - filterTransforms = require('../filters/filterTransforms'), - bitTwiddle = require('bit-twiddle'); - -class FilterState { +class FilterState +{ constructor() { this.renderTarget = null; @@ -25,7 +25,8 @@ * @extends PIXI.WebGLManager * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class FilterManager extends WebGLManager { +class FilterManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -437,7 +438,6 @@ let key = ((minWidth & 0xFFFF) << 16) | (minHeight & 0xFFFF); this.pool[key].push(renderTarget); } - } -module.exports = FilterManager; +export default FilterManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/MaskManager.js b/src/core/renderers/webgl/managers/MaskManager.js index 3fcf89c..d4a1f0a 100644 --- a/src/core/renderers/webgl/managers/MaskManager.js +++ b/src/core/renderers/webgl/managers/MaskManager.js @@ -1,12 +1,13 @@ -let WebGLManager = require('./WebGLManager'), - AlphaMaskFilter = require('../filters/spriteMask/SpriteMaskFilter'); +import WebGLManager from './WebGLManager'; +import AlphaMaskFilter from '../filters/spriteMask/SpriteMaskFilter'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class MaskManager extends WebGLManager { +class MaskManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -188,7 +189,6 @@ let gl = this.renderer.gl; gl.disable(gl.SCISSOR_TEST); } - } -module.exports = MaskManager; +export default MaskManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/StencilManager.js b/src/core/renderers/webgl/managers/StencilManager.js index de2f3cf..343c851 100644 --- a/src/core/renderers/webgl/managers/StencilManager.js +++ b/src/core/renderers/webgl/managers/StencilManager.js @@ -1,11 +1,12 @@ -let WebGLManager = require('./WebGLManager'); +import WebGLManager from './WebGLManager'; /** * @class * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class StencilManager extends WebGLManager { +class StencilManager extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -106,7 +107,6 @@ this.stencilMaskStack.stencilStack = null; } - } -module.exports = StencilManager; +export default StencilManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/managers/WebGLManager.js b/src/core/renderers/webgl/managers/WebGLManager.js index f9a0f52..a16a032 100644 --- a/src/core/renderers/webgl/managers/WebGLManager.js +++ b/src/core/renderers/webgl/managers/WebGLManager.js @@ -3,7 +3,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this manager works for. */ -class WebGLManager { +class WebGLManager +{ constructor(renderer) { /** @@ -35,7 +36,6 @@ this.renderer = null; } - } -module.exports = WebGLManager; +export default WebGLManager; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/ObjectRenderer.js b/src/core/renderers/webgl/utils/ObjectRenderer.js index 98d1504..8825026 100644 --- a/src/core/renderers/webgl/utils/ObjectRenderer.js +++ b/src/core/renderers/webgl/utils/ObjectRenderer.js @@ -1,4 +1,4 @@ -let WebGLManager = require('../managers/WebGLManager'); +import WebGLManager from '../managers/WebGLManager'; /** * Base for a common object renderer that can be used as a system renderer plugin. @@ -8,7 +8,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this object renderer works for. */ -class ObjectRenderer extends WebGLManager { +class ObjectRenderer extends WebGLManager +{ constructor(renderer) { super(renderer); @@ -50,7 +51,6 @@ { // render the object } - } -module.exports = ObjectRenderer; +export default ObjectRenderer; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/Quad.js b/src/core/renderers/webgl/utils/Quad.js index 6849993..b15ea3d 100644 --- a/src/core/renderers/webgl/utils/Quad.js +++ b/src/core/renderers/webgl/utils/Quad.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../../utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../../utils/createIndicesForQuads'; /** * Helper class to create a quad @@ -9,7 +9,8 @@ * @param gl {WebGLRenderingContext} The gl context for this quad to use. * @param state {object} TODO: Description */ -class Quad { +class Quad +{ constructor(gl, state) { /* @@ -166,7 +167,6 @@ gl.deleteBuffer(this.vertexBuffer); gl.deleteBuffer(this.indexBuffer); } - } -module.exports = Quad; +export default Quad; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/RenderTarget.js b/src/core/renderers/webgl/utils/RenderTarget.js index 8133651..4adc307 100644 --- a/src/core/renderers/webgl/utils/RenderTarget.js +++ b/src/core/renderers/webgl/utils/RenderTarget.js @@ -1,10 +1,6 @@ -let math = require('../../../math'), - CONST = require('../../../const'), - GLFramebuffer = require('pixi-gl-core').GLFramebuffer; - -/** - * @author Mat Groves http://matgroves.com/ @Doormat23 - */ +import math from '../../../math'; +import CONST from '../../../const'; +import {GLFramebuffer} from 'pixi-gl-core'; /** * @class @@ -16,7 +12,8 @@ * @param [resolution=1] {number} The current resolution / device pixel ratio * @param [root=false] {boolean} Whether this object is the root element or not */ -class RenderTarget { +class RenderTarget +{ constructor(gl, width, height, scaleMode, resolution, root) { //TODO Resolution could go here ( eg low res blurs ) @@ -314,7 +311,6 @@ this.frameBuffer = null; this.texture = null; } - } -module.exports = RenderTarget; +export default RenderTarget; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js index ee2c663..7b36a62 100644 --- a/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js +++ b/src/core/renderers/webgl/utils/checkMaxIfStatmentsInShader.js @@ -1,6 +1,6 @@ -let glCore = require('pixi-gl-core'); +import glCore from 'pixi-gl-core'; -let fragTemplate = [ +const fragTemplate = [ 'precision mediump float;', 'void main(void){', 'float test = 0.1;', @@ -9,7 +9,7 @@ '}' ].join('\n'); -let checkMaxIfStatmentsInShader = function(maxIfs, gl) +const checkMaxIfStatmentsInShader = function(maxIfs, gl) { let createTempContext = !gl; @@ -55,7 +55,6 @@ }; - function generateIfTestSrc(maxIfs) { let src = ''; @@ -76,4 +75,4 @@ return src; } -module.exports = checkMaxIfStatmentsInShader; +export default checkMaxIfStatmentsInShader; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js index c6f67d4..f0c69c0 100644 --- a/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLBlendModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Maps gl blend combinations to WebGL @@ -34,4 +34,4 @@ return array; } -module.exports = mapWebGLBlendModesToPixi; +export default mapWebGLBlendModesToPixi; diff --git a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js index 423498b..3cf004d 100644 --- a/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js +++ b/src/core/renderers/webgl/utils/mapWebGLDrawModesToPixi.js @@ -1,4 +1,4 @@ -let CONST = require('../../../const'); +import CONST from '../../../const'; /** * Generic Mask Stack data structure @@ -18,7 +18,6 @@ object[CONST.DRAW_MODES.TRIANGLES] = gl.TRIANGLES; object[CONST.DRAW_MODES.TRIANGLE_STRIP] = gl.TRIANGLE_STRIP; object[CONST.DRAW_MODES.TRIANGLE_FAN] = gl.TRIANGLE_FAN; - } -module.exports = mapWebGLDrawModesToPixi; +export default mapWebGLDrawModesToPixi; \ No newline at end of file diff --git a/src/core/renderers/webgl/utils/validateContext.js b/src/core/renderers/webgl/utils/validateContext.js index 41ad208..f2ef846 100644 --- a/src/core/renderers/webgl/utils/validateContext.js +++ b/src/core/renderers/webgl/utils/validateContext.js @@ -1,5 +1,3 @@ - - function validateContext(gl) { let attributes = gl.getContextAttributes(); @@ -11,4 +9,4 @@ } } -module.exports = validateContext; +export default validateContext; \ No newline at end of file diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 7df7fed..356b45a 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -1,9 +1,10 @@ -let math = require('../math'), - Texture = require('../textures/Texture'), - Container = require('../display/Container'), - utils = require('../utils'), - CONST = require('../const'), - tempPoint = new math.Point(); +import math from '../math'; +import Texture from '../textures/Texture'; +import Container from '../display/Container'; +import utils from '../utils'; +import CONST from '../const'; + +const tempPoint = new math.Point(); /** * The Sprite object is the base for all textured objects that are rendered to the screen @@ -19,7 +20,8 @@ * @memberof PIXI * @param texture {PIXI.Texture} The texture for this sprite */ -class Sprite extends Container { +class Sprite extends Container +{ constructor(texture) { super(); @@ -429,29 +431,22 @@ return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); } -} - -module.exports = Sprite; - -Object.defineProperties(Sprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Sprite# */ - width: { - get: function () - { - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + get width() + { + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the sprite, setting this will actually modify the scale to achieve the value set @@ -459,30 +454,26 @@ * @member {number} * @memberof PIXI.Sprite# */ - height: { - get: function () - { - return Math.abs(this.scale.y) * this.texture.orig.height; - }, - set: function (value) - { - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + get height() + { + return Math.abs(this.scale.y) * this.texture.orig.height; + } + set height(value) + { + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } - tint: { - get: function () - { - return this._tint; - }, - set: function (value) - { - this._tint = value; - this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); - } - }, + get tint() + { + return this._tint; + } + set tint(value) + { + this._tint = value; + this._tintRGB = (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16); + } /** * The texture that the sprite is using @@ -490,35 +481,35 @@ * @member {PIXI.Texture} * @memberof PIXI.Sprite# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + this.cachedTint = 0xFFFFFF; + + this._textureID = -1; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - this.cachedTint = 0xFFFFFF; - - this._textureID = -1; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } } -}); +} + +export default Sprite; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasSpriteRenderer.js b/src/core/sprites/canvas/CanvasSpriteRenderer.js index 37e3bc1..e5c53a7 100644 --- a/src/core/sprites/canvas/CanvasSpriteRenderer.js +++ b/src/core/sprites/canvas/CanvasSpriteRenderer.js @@ -1,8 +1,9 @@ -let CanvasRenderer = require('../../renderers/canvas/CanvasRenderer'), - CONST = require('../../const'), - math = require('../../math'), - canvasRenderWorldTransform = new math.Matrix(), - CanvasTinter = require('./CanvasTinter'); +import CanvasRenderer from '../../renderers/canvas/CanvasRenderer'; +import CONST from '../../const'; +import math from '../../math'; +import CanvasTinter from './CanvasTinter'; + +const canvasRenderWorldTransform = new math.Matrix(); /** * @author Mat Groves @@ -24,7 +25,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer sprite this batch works for. */ -class CanvasSpriteRenderer { +class CanvasSpriteRenderer +{ constructor(renderer) { this.renderer = renderer; @@ -154,12 +156,12 @@ * destroy the sprite object. * */ - destroy() { - this.renderer = null; + destroy() + { + this.renderer = null; } - } -module.exports = CanvasSpriteRenderer; - CanvasRenderer.registerPlugin('sprite', CanvasSpriteRenderer); + +export default CanvasSpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/canvas/CanvasTinter.js b/src/core/sprites/canvas/CanvasTinter.js index 37a5b51..8f910e0 100644 --- a/src/core/sprites/canvas/CanvasTinter.js +++ b/src/core/sprites/canvas/CanvasTinter.js @@ -1,12 +1,12 @@ -let utils = require('../../utils'), - canUseNewCanvasBlendModes = require('../../renderers/canvas/utils/canUseNewCanvasBlendModes'); +import utils from '../../utils'; +import canUseNewCanvasBlendModes from '../../renderers/canvas/utils/canUseNewCanvasBlendModes'; /** * Utility methods for Sprite/Texture tinting. * * @namespace PIXI.CanvasTinter */ -let CanvasTinter = module.exports = { +const CanvasTinter = { /** * Basically this method just needs a sprite and a color and tints the sprite with the given color. * @@ -266,3 +266,5 @@ * @param color {number} the color to use to tint the sprite with * @param canvas {HTMLCanvasElement} the current canvas */ + +export default CanvasTinter; \ No newline at end of file diff --git a/src/core/sprites/webgl/BatchBuffer.js b/src/core/sprites/webgl/BatchBuffer.js index 505ea2c..4dc9655 100644 --- a/src/core/sprites/webgl/BatchBuffer.js +++ b/src/core/sprites/webgl/BatchBuffer.js @@ -1,30 +1,31 @@ +class Buffer +{ + constructor(size) + { + this.vertices = new ArrayBuffer(size); + /** + * View on the vertices as a Float32Array for positions + * + * @member {Float32Array} + */ + this.float32View = new Float32Array(this.vertices); - let Buffer = function(size) - { + /** + * View on the vertices as a Uint32Array for uvs + * + * @member {Float32Array} + */ + this.uint32View = new Uint32Array(this.vertices); + } - this.vertices = new ArrayBuffer(size); + destroy() + { + this.vertices = null; + this.positions = null; + this.uvs = null; + this.colors = null; + } +} - /** - * View on the vertices as a Float32Array for positions - * - * @member {Float32Array} - */ - this.float32View = new Float32Array(this.vertices); - - /** - * View on the vertices as a Uint32Array for uvs - * - * @member {Float32Array} - */ - this.uint32View = new Uint32Array(this.vertices); - }; - - module.exports = Buffer; - - Buffer.prototype.destroy = function(){ - this.vertices = null; - this.positions = null; - this.uvs = null; - this.colors = null; - }; \ No newline at end of file +export default Buffer; \ No newline at end of file diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index 46a1bb8..db0b30d 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -1,14 +1,15 @@ -let ObjectRenderer = require('../../renderers/webgl/utils/ObjectRenderer'), - WebGLRenderer = require('../../renderers/webgl/WebGLRenderer'), - createIndicesForQuads = require('../../utils/createIndicesForQuads'), - generateMultiTextureShader = require('./generateMultiTextureShader'), - checkMaxIfStatmentsInShader = require('../../renderers/webgl/utils/checkMaxIfStatmentsInShader'), - Buffer = require('./BatchBuffer'), - CONST = require('../../const'), - glCore = require('pixi-gl-core'), - bitTwiddle = require('bit-twiddle'); +import ObjectRenderer from '../../renderers/webgl/utils/ObjectRenderer'; +import WebGLRenderer from '../../renderers/webgl/WebGLRenderer'; +import createIndicesForQuads from '../../utils/createIndicesForQuads'; +import generateMultiTextureShader from './generateMultiTextureShader'; +import checkMaxIfStatmentsInShader from '../../renderers/webgl/utils/checkMaxIfStatmentsInShader'; +import Buffer from './BatchBuffer'; +import CONST from '../../const'; +import glCore from 'pixi-gl-core'; +import bitTwiddle from 'bit-twiddle'; - let TICK = 0; +let TICK = 0; + /** * Renderer dedicated to drawing and batching sprites. * @@ -18,7 +19,8 @@ * @extends PIXI.ObjectRenderer * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class SpriteRenderer extends ObjectRenderer { +class SpriteRenderer extends ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -415,11 +417,9 @@ for (let i = 0; i < this.buffers.length; i++) { this.buffers[i].destroy(); } - } - } -module.exports = SpriteRenderer; - WebGLRenderer.registerPlugin('sprite', SpriteRenderer); + +export default SpriteRenderer; \ No newline at end of file diff --git a/src/core/sprites/webgl/generateMultiTextureShader.js b/src/core/sprites/webgl/generateMultiTextureShader.js index 680412f..e76c321 100644 --- a/src/core/sprites/webgl/generateMultiTextureShader.js +++ b/src/core/sprites/webgl/generateMultiTextureShader.js @@ -1,7 +1,7 @@ -let Shader = require('../../Shader'); -let glslify = require('glslify'); +import Shader from '../../Shader'; +const glslify = require('glslify'); -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vTextureCoord;', 'varying vec4 vColor;', 'varying float vTextureId;', @@ -67,6 +67,4 @@ return src; } - - -module.exports = generateMultiTextureShader; +export default generateMultiTextureShader; \ No newline at end of file diff --git a/src/core/text/Text.js b/src/core/text/Text.js index 1404884..8e2f303 100644 --- a/src/core/text/Text.js +++ b/src/core/text/Text.js @@ -1,15 +1,16 @@ -let Sprite = require('../sprites/Sprite'), - Texture = require('../textures/Texture'), - math = require('../math'), - utils = require('../utils'), - CONST = require('../const'), - TextStyle = require('./TextStyle'); +import Sprite from '../sprites/Sprite'; +import Texture from '../textures/Texture'; +import math from '../math'; +import utils from '../utils'; +import CONST from '../const'; +import TextStyle from './TextStyle'; - let defaultDestroyOptions = { - texture:true, - children:false, - baseTexture:true - }; +const defaultDestroyOptions = { + texture:true, + children:false, + baseTexture:true +}; + /** * A Text Object will create a line or multiple lines of text. To split a line you can use '\n' in your text string, * or add a wordWrap property set to true and and wordWrapWidth property with a value in the style object. @@ -26,7 +27,8 @@ * @param text {string} The string that you would like the text to display * @param [style] {object|PIXI.TextStyle} The style parameters */ -class Text extends Sprite { +class Text extends Sprite +{ constructor(text, style) { let texture = Texture.fromCanvas(document.createElement('canvas')); @@ -662,37 +664,26 @@ this._style = null; } -} - -module.exports = Text; - -Text.fontPropertiesCache = {}; -Text.fontPropertiesCanvas = document.createElement('canvas'); -Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); - -Object.defineProperties(Text.prototype, { /** * The width of the Text, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.Text# */ - width: { - get: function () - { - this.updateText(true); + get width() + { + this.updateText(true); - return Math.abs(this.scale.x) * this.texture.orig.width; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.x) * this.texture.orig.width; + } + set width(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.x) || 1; - this.scale.x = sign * value / this.texture.orig.width; - this._width = value; - } - }, + let sign = utils.sign(this.scale.x) || 1; + this.scale.x = sign * value / this.texture.orig.width; + this._width = value; + } /** * The height of the Text, setting this will actually modify the scale to achieve the value set @@ -700,22 +691,20 @@ * @member {number} * @memberof PIXI.Text# */ - height: { - get: function () - { - this.updateText(true); + get height() + { + this.updateText(true); - return Math.abs(this.scale.y) * this._texture.orig.height; - }, - set: function (value) - { - this.updateText(true); + return Math.abs(this.scale.y) * this._texture.orig.height; + } + set height(value) + { + this.updateText(true); - let sign = utils.sign(this.scale.y) || 1; - this.scale.y = sign * value / this.texture.orig.height; - this._height = value; - } - }, + let sign = utils.sign(this.scale.y) || 1; + this.scale.y = sign * value / this.texture.orig.height; + this._height = value; + } /** * Set the style of the text. Set up an event listener to listen for changes on the style object and mark the text as dirty. @@ -723,28 +712,26 @@ * @member {object|PIXI.TextStyle} * @memberof PIXI.Text# */ - style: { - get: function () - { - return this._style; - }, - set: function (style) - { + get style() + { + return this._style; + } + set style(style) + { - style = style || {}; - if (style instanceof TextStyle) - { - this._style = style; - } - else - { - this._style = new TextStyle(style); - } - - this.localStyleID = -1; - this.dirty = true; + style = style || {}; + if (style instanceof TextStyle) + { + this._style = style; } - }, + else + { + this._style = new TextStyle(style); + } + + this.localStyleID = -1; + this.dirty = true; + } /** * Set the copy for the text object. To split a line you can use '\n'. @@ -752,22 +739,27 @@ * @member {string} * @memberof PIXI.Text# */ - text: { - get: function() - { - return this._text; - }, - set: function (text){ - - text = text || ' '; - text = text.toString(); - - if (this._text === text) - { - return; - } - this._text = text; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(text) + { + + text = text || ' '; + text = text.toString(); + + if (this._text === text) + { + return; + } + this._text = text; + this.dirty = true; + } +} + +Text.fontPropertiesCache = {}; +Text.fontPropertiesCanvas = document.createElement('canvas'); +Text.fontPropertiesContext = Text.fontPropertiesCanvas.getContext('2d'); + +export default Text; \ No newline at end of file diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 19dd4b2..d9cb03c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -1,5 +1,5 @@ -let CONST = require('../const'), - utils = require('../utils'); +import CONST from '../const'; +import utils from '../utils'; /** * A TextStyle Object decorates a Text Object. It can be shared between @@ -37,7 +37,8 @@ * @param [style.wordWrap=false] {boolean} Indicates if word wrap should be used * @param [style.wordWrapWidth=100] {number} The width at which text will wrap, it needs wordWrap to be set to true */ -class TextStyle { +class TextStyle +{ constructor(style) { this.styleID = 0; @@ -68,405 +69,357 @@ Object.assign(this, this._defaults); } -} - -module.exports = TextStyle; - -// Default settings. Explained in the constructor. -TextStyle.prototype._defaults = { - align: 'left', - breakWords: false, - dropShadow: false, - dropShadowAngle: Math.PI / 6, - dropShadowBlur: 0, - dropShadowColor: '#000000', - dropShadowDistance: 5, - fill: 'black', - fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, - fontFamily: 'Arial', - fontSize: 26, - fontStyle: 'normal', - fontVariant: 'normal', - fontWeight: 'normal', - letterSpacing: 0, - lineHeight: 0, - lineJoin: 'miter', - miterLimit: 10, - padding: 0, - stroke: 'black', - strokeThickness: 0, - textBaseline: 'alphabetic', - wordWrap: false, - wordWrapWidth: 100 -}; + // Default settings. Explained in the constructor. + get _defaults() + { + return { + align: 'left', + breakWords: false, + dropShadow: false, + dropShadowAngle: Math.PI / 6, + dropShadowBlur: 0, + dropShadowColor: '#000000', + dropShadowDistance: 5, + fill: 'black', + fillGradientType: CONST.TEXT_GRADIENT.LINEAR_VERTICAL, + fontFamily: 'Arial', + fontSize: 26, + fontStyle: 'normal', + fontVariant: 'normal', + fontWeight: 'normal', + letterSpacing: 0, + lineHeight: 0, + lineJoin: 'miter', + miterLimit: 10, + padding: 0, + stroke: 'black', + strokeThickness: 0, + textBaseline: 'alphabetic', + wordWrap: false, + wordWrapWidth: 100 + }; + } /** * Create setters and getters for each of the style properties. Converts colors where necessary. */ -Object.defineProperties(TextStyle.prototype, { - align: { - get: function () - { - return this._align; - }, - set: function (align) - { - if (this._align !== align) - { - this._align = align; - this.styleID++; - } - } - }, - breakWords: { - get: function () + get align() + { + return this._align; + } + set align(align) + { + if (this._align !== align) { - return this._breakWords; - }, - set: function (breakWords) - { - if (this._breakWords !== breakWords) - { - this._breakWords = breakWords; - this.styleID++; - } - } - }, - - dropShadow: { - get: function () - { - return this._dropShadow; - }, - set: function (dropShadow) - { - if (this._dropShadow !== dropShadow) - { - this._dropShadow = dropShadow; - this.styleID++; - } - } - }, - - dropShadowAngle: { - get: function () - { - return this._dropShadowAngle; - }, - set: function (dropShadowAngle) - { - if (this._dropShadowAngle !== dropShadowAngle) - { - this._dropShadowAngle = dropShadowAngle; - this.styleID++; - } - } - }, - - dropShadowBlur: { - get: function () - { - return this._dropShadowBlur; - }, - set: function (dropShadowBlur) - { - if (this._dropShadowBlur !== dropShadowBlur) - { - this._dropShadowBlur = dropShadowBlur; - this.styleID++; - } - } - }, - - dropShadowColor: { - get: function () - { - return this._dropShadowColor; - }, - set: function (dropShadowColor) - { - let outputColor = getColor(dropShadowColor); - if (this._dropShadowColor !== outputColor) - { - this._dropShadowColor = outputColor; - this.styleID++; - } - } - }, - - dropShadowDistance: { - get: function () - { - return this._dropShadowDistance; - }, - set: function (dropShadowDistance) - { - if (this._dropShadowDistance !== dropShadowDistance) - { - this._dropShadowDistance = dropShadowDistance; - this.styleID++; - } - } - }, - - fill: { - get: function () - { - return this._fill; - }, - set: function (fill) - { - let outputColor = getColor(fill); - if (this._fill !== outputColor) - { - this._fill = outputColor; - this.styleID++; - } - } - }, - - fillGradientType: { - get: function () - { - return this._fillGradientType; - }, - set: function (fillGradientType) - { - if (this._fillGradientType !== fillGradientType) - { - this._fillGradientType = fillGradientType; - this.styleID++; - } - } - }, - - fontFamily: { - get: function () - { - return this._fontFamily; - }, - set: function (fontFamily) - { - if (this.fontFamily !== fontFamily) - { - this._fontFamily = fontFamily; - this.styleID++; - } - } - }, - - fontSize: { - get: function () - { - return this._fontSize; - }, - set: function (fontSize) - { - if (this._fontSize !== fontSize) - { - this._fontSize = fontSize; - this.styleID++; - } - } - }, - - fontStyle: { - get: function () - { - return this._fontStyle; - }, - set: function (fontStyle) - { - if (this._fontStyle !== fontStyle) - { - this._fontStyle = fontStyle; - this.styleID++; - } - } - }, - - fontVariant: { - get: function () - { - return this._fontVariant; - }, - set: function (fontVariant) - { - if (this._fontVariant !== fontVariant) - { - this._fontVariant = fontVariant; - this.styleID++; - } - } - }, - - fontWeight: { - get: function () - { - return this._fontWeight; - }, - set: function (fontWeight) - { - if (this._fontWeight !== fontWeight) - { - this._fontWeight = fontWeight; - this.styleID++; - } - } - }, - - letterSpacing: { - get: function () - { - return this._letterSpacing; - }, - set: function (letterSpacing) - { - if (this._letterSpacing !== letterSpacing) - { - this._letterSpacing = letterSpacing; - this.styleID++; - } - } - }, - - lineHeight: { - get: function () - { - return this._lineHeight; - }, - set: function (lineHeight) - { - if (this._lineHeight !== lineHeight) - { - this._lineHeight = lineHeight; - this.styleID++; - } - } - }, - - lineJoin: { - get: function () - { - return this._lineJoin; - }, - set: function (lineJoin) - { - if (this._lineJoin !== lineJoin) - { - this._lineJoin = lineJoin; - this.styleID++; - } - } - }, - - miterLimit: { - get: function () - { - return this._miterLimit; - }, - set: function (miterLimit) - { - if (this._miterLimit !== miterLimit) - { - this._miterLimit = miterLimit; - this.styleID++; - } - } - }, - - padding: { - get: function () - { - return this._padding; - }, - set: function (padding) - { - if (this._padding !== padding) - { - this._padding = padding; - this.styleID++; - } - } - }, - - stroke: { - get: function () - { - return this._stroke; - }, - set: function (stroke) - { - let outputColor = getColor(stroke); - if (this._stroke !== outputColor) - { - this._stroke = outputColor; - this.styleID++; - } - } - }, - - strokeThickness: { - get: function () - { - return this._strokeThickness; - }, - set: function (strokeThickness) - { - if (this._strokeThickness !== strokeThickness) - { - this._strokeThickness = strokeThickness; - this.styleID++; - } - } - }, - - textBaseline: { - get: function () - { - return this._textBaseline; - }, - set: function (textBaseline) - { - if (this._textBaseline !== textBaseline) - { - this._textBaseline = textBaseline; - this.styleID++; - } - } - }, - - wordWrap: { - get: function () - { - return this._wordWrap; - }, - set: function (wordWrap) - { - if (this._wordWrap !== wordWrap) - { - this._wordWrap = wordWrap; - this.styleID++; - } - } - }, - - wordWrapWidth: { - get: function () - { - return this._wordWrapWidth; - }, - set: function (wordWrapWidth) - { - if (this._wordWrapWidth !== wordWrapWidth) - { - this._wordWrapWidth = wordWrapWidth; - this.styleID++; - } + this._align = align; + this.styleID++; } } -}); + + get breakWords() + { + return this._breakWords; + } + set breakWords(breakWords) + { + if (this._breakWords !== breakWords) + { + this._breakWords = breakWords; + this.styleID++; + } + } + + get dropShadow() + { + return this._dropShadow; + } + set dropShadow(dropShadow) + { + if (this._dropShadow !== dropShadow) + { + this._dropShadow = dropShadow; + this.styleID++; + } + } + + get dropShadowAngle() + { + return this._dropShadowAngle; + } + set dropShadowAngle(dropShadowAngle) + { + if (this._dropShadowAngle !== dropShadowAngle) + { + this._dropShadowAngle = dropShadowAngle; + this.styleID++; + } + } + + get dropShadowBlur() + { + return this._dropShadowBlur; + } + set dropShadowBlur(dropShadowBlur) + { + if (this._dropShadowBlur !== dropShadowBlur) + { + this._dropShadowBlur = dropShadowBlur; + this.styleID++; + } + } + + get dropShadowColor() + { + return this._dropShadowColor; + } + set dropShadowColor(dropShadowColor) + { + let outputColor = getColor(dropShadowColor); + if (this._dropShadowColor !== outputColor) + { + this._dropShadowColor = outputColor; + this.styleID++; + } + } + + get dropShadowDistance() + { + return this._dropShadowDistance; + } + set dropShadowDistance(dropShadowDistance) + { + if (this._dropShadowDistance !== dropShadowDistance) + { + this._dropShadowDistance = dropShadowDistance; + this.styleID++; + } + } + + get fill() + { + return this._fill; + } + set fill(fill) + { + let outputColor = getColor(fill); + if (this._fill !== outputColor) + { + this._fill = outputColor; + this.styleID++; + } + } + + get fillGradientType() + { + return this._fillGradientType; + } + set fillGradientType(fillGradientType) + { + if (this._fillGradientType !== fillGradientType) + { + this._fillGradientType = fillGradientType; + this.styleID++; + } + } + + get fontFamily() + { + return this._fontFamily; + } + set fontFamily(fontFamily) + { + if (this.fontFamily !== fontFamily) + { + this._fontFamily = fontFamily; + this.styleID++; + } + } + + get fontSize() + { + return this._fontSize; + } + set fontSize(fontSize) + { + if (this._fontSize !== fontSize) + { + this._fontSize = fontSize; + this.styleID++; + } + } + + get fontStyle() + { + return this._fontStyle; + } + set fontStyle(fontStyle) + { + if (this._fontStyle !== fontStyle) + { + this._fontStyle = fontStyle; + this.styleID++; + } + } + + get fontVariant() + { + return this._fontVariant; + } + set fontVariant(fontVariant) + { + if (this._fontVariant !== fontVariant) + { + this._fontVariant = fontVariant; + this.styleID++; + } + } + + get fontWeight() + { + return this._fontWeight; + } + set fontWeight(fontWeight) + { + if (this._fontWeight !== fontWeight) + { + this._fontWeight = fontWeight; + this.styleID++; + } + } + + get letterSpacing() + { + return this._letterSpacing; + } + set letterSpacing(letterSpacing) + { + if (this._letterSpacing !== letterSpacing) + { + this._letterSpacing = letterSpacing; + this.styleID++; + } + } + + get lineHeight() + { + return this._lineHeight; + } + set lineHeight(lineHeight) + { + if (this._lineHeight !== lineHeight) + { + this._lineHeight = lineHeight; + this.styleID++; + } + } + + get lineJoin() + { + return this._lineJoin; + } + set lineJoin(lineJoin) + { + if (this._lineJoin !== lineJoin) + { + this._lineJoin = lineJoin; + this.styleID++; + } + } + + get miterLimit() + { + return this._miterLimit; + } + set miterLimit(miterLimit) + { + if (this._miterLimit !== miterLimit) + { + this._miterLimit = miterLimit; + this.styleID++; + } + } + + get padding() + { + return this._padding; + } + set padding(padding) + { + if (this._padding !== padding) + { + this._padding = padding; + this.styleID++; + } + } + + get stroke() + { + return this._stroke; + } + set stroke(stroke) + { + let outputColor = getColor(stroke); + if (this._stroke !== outputColor) + { + this._stroke = outputColor; + this.styleID++; + } + } + + get strokeThickness() + { + return this._strokeThickness; + } + set strokeThickness(strokeThickness) + { + if (this._strokeThickness !== strokeThickness) + { + this._strokeThickness = strokeThickness; + this.styleID++; + } + } + + get textBaseline() + { + return this._textBaseline; + } + set textBaseline(textBaseline) + { + if (this._textBaseline !== textBaseline) + { + this._textBaseline = textBaseline; + this.styleID++; + } + } + + get wordWrap() + { + return this._wordWrap; + } + set wordWrap(wordWrap) + { + if (this._wordWrap !== wordWrap) + { + this._wordWrap = wordWrap; + this.styleID++; + } + } + + get wordWrapWidth() + { + return this._wordWrapWidth; + } + set wordWrapWidth(wordWrapWidth) + { + if (this._wordWrapWidth !== wordWrapWidth) + { + this._wordWrapWidth = wordWrapWidth; + this.styleID++; + } + } +} + /** * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. @@ -492,3 +445,5 @@ return color; } + +export default TextStyle; diff --git a/src/core/textures/BaseRenderTexture.js b/src/core/textures/BaseRenderTexture.js index 3fcb3b7..f56b90f 100644 --- a/src/core/textures/BaseRenderTexture.js +++ b/src/core/textures/BaseRenderTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - CONST = require('../const'); +import BaseTexture from './BaseTexture'; +import CONST from '../const'; /** * A BaseRenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -45,7 +45,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture being generated */ -class BaseRenderTexture extends BaseTexture { +class BaseRenderTexture extends BaseTexture +{ constructor(width, height, scaleMode, resolution) { super(null, scaleMode); @@ -125,7 +126,6 @@ super.destroy(true); this.renderer = null; } - } -module.exports = BaseRenderTexture; +export default BaseRenderTexture; \ No newline at end of file diff --git a/src/core/textures/BaseTexture.js b/src/core/textures/BaseTexture.js index c018b8f..6071868 100644 --- a/src/core/textures/BaseTexture.js +++ b/src/core/textures/BaseTexture.js @@ -1,8 +1,8 @@ -let utils = require('../utils'), - CONST = require('../const'), - EventEmitter = require('eventemitter3'), - determineCrossOrigin = require('../utils/determineCrossOrigin'), - bitTwiddle = require('bit-twiddle'); +import utils from '../utils'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import determineCrossOrigin from '../utils/determineCrossOrigin'; +import bitTwiddle from 'bit-twiddle'; /** * A texture stores the information that represents an image. All textures have a base texture. @@ -13,7 +13,8 @@ * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values * @param [resolution=1] {number} The resolution / device pixel ratio of the texture */ -class BaseTexture extends EventEmitter { +class BaseTexture extends EventEmitter +{ constructor(source, scaleMode, resolution) { super(); @@ -443,7 +444,6 @@ return baseTexture; } - } -module.exports = BaseTexture; +export default BaseTexture; \ No newline at end of file diff --git a/src/core/textures/RenderTexture.js b/src/core/textures/RenderTexture.js index a481162..38233d5 100644 --- a/src/core/textures/RenderTexture.js +++ b/src/core/textures/RenderTexture.js @@ -1,5 +1,5 @@ -let BaseRenderTexture = require('./BaseRenderTexture'), - Texture = require('./Texture'); +import BaseRenderTexture from './BaseRenderTexture'; +import Texture from './Texture'; /** * A RenderTexture is a special texture that allows any Pixi display object to be rendered to it. @@ -40,7 +40,8 @@ * @param baseRenderTexture {PIXI.BaseRenderTexture} The renderer used for this RenderTexture * @param [frame] {PIXI.Rectangle} The rectangle frame of the texture to show */ -class RenderTexture extends Texture { +class RenderTexture extends Texture +{ constructor(baseRenderTexture, frame) { // suport for legacy.. @@ -119,7 +120,6 @@ { return new RenderTexture(new BaseRenderTexture(width, height, scaleMode, resolution)); } - } -module.exports = RenderTexture; +export default RenderTexture; \ No newline at end of file diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index 009b52b..a7502c8 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -1,9 +1,9 @@ -let BaseTexture = require('./BaseTexture'), - VideoBaseTexture = require('./VideoBaseTexture'), - TextureUvs = require('./TextureUvs'), - EventEmitter = require('eventemitter3'), - math = require('../math'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import VideoBaseTexture from './VideoBaseTexture'; +import TextureUvs from './TextureUvs'; +import EventEmitter from 'eventemitter3'; +import math from '../math'; +import utils from '../utils'; /** * A texture stores the information that represents an image or part of an image. It cannot be added @@ -25,7 +25,8 @@ * @param [trim] {PIXI.Rectangle} Trimmed rectangle of original texture * @param [rotate] {number} indicates how the texture was rotated by texture packer. See {@link PIXI.GroupD8} */ -class Texture extends EventEmitter { +class Texture extends EventEmitter +{ constructor(baseTexture, frame, orig, trim, rotate) { super(); @@ -420,47 +421,41 @@ return texture; } -} - -module.exports = Texture; - -Object.defineProperties(Texture.prototype, { /** * The frame specifies the region of the base texture that this texture uses. * * @member {PIXI.Rectangle} * @memberof PIXI.Texture# */ - frame: { - get: function () + get frame() + { + return this._frame; + } + set frame(frame) + { + this._frame = frame; + + this.noFrame = false; + + if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) { - return this._frame; - }, - set: function (frame) - { - this._frame = frame; - - this.noFrame = false; - - if (frame.x + frame.width > this.baseTexture.width || frame.y + frame.height > this.baseTexture.height) - { - throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); - } - - //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; - this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; - - if (!this.trim && !this.rotate) - { - this.orig = frame; - } - - if (this.valid) - { - this._updateUvs(); - } + throw new Error('Texture Error: frame does not fit inside the base Texture dimensions ' + this); } - }, + + //this.valid = frame && frame.width && frame.height && this.baseTexture.source && this.baseTexture.hasLoaded; + this.valid = frame && frame.width && frame.height && this.baseTexture.hasLoaded; + + if (!this.trim && !this.rotate) + { + this.orig = frame; + } + + if (this.valid) + { + this._updateUvs(); + } + } + /** * Indicates whether the texture is rotated inside the atlas * set to 2 to compensate for texture packer rotation @@ -470,43 +465,37 @@ * * @member {number} */ - rotate: { - get: function () + get rotate() + { + return this._rotate; + } + set rotate(rotate) + { + this._rotate = rotate; + if (this.valid) { - return this._rotate; - }, - set: function (rotate) - { - this._rotate = rotate; - if (this.valid) - { - this._updateUvs(); - } + this._updateUvs(); } - }, + } /** * The width of the Texture in pixels. * * @member {number} */ - width: { - get: function() { - return this.orig ? this.orig.width : 0; - } - }, + get width() { + return this.orig ? this.orig.width : 0; + } /** * The height of the Texture in pixels. * * @member {number} */ - height: { - get: function() { - return this.orig ? this.orig.height : 0; - } + get height() { + return this.orig ? this.orig.height : 0; } -}); +} /** * An empty texture, used often to not have to create multiple empty textures. @@ -521,3 +510,4 @@ Texture.EMPTY.once = function() {}; Texture.EMPTY.emit = function() {}; +export default Texture; \ No newline at end of file diff --git a/src/core/textures/TextureUvs.js b/src/core/textures/TextureUvs.js index 285dd0a..a752c0e 100644 --- a/src/core/textures/TextureUvs.js +++ b/src/core/textures/TextureUvs.js @@ -1,4 +1,4 @@ -let GroupD8 = require('../math/GroupD8'); +import GroupD8 from '../math/GroupD8'; /** * A standard object to store the Uvs of a texture @@ -7,7 +7,8 @@ * @private * @memberof PIXI */ -class TextureUvs { +class TextureUvs +{ constructor() { this.x0 = 0; @@ -79,7 +80,6 @@ this.uvsUint32[2] = (((this.y2 * 65535) & 0xFFFF) << 16) | ((this.x2 * 65535) & 0xFFFF); this.uvsUint32[3] = (((this.y3 * 65535) & 0xFFFF) << 16) | ((this.x3 * 65535) & 0xFFFF); } - } -module.exports = TextureUvs; +export default TextureUvs; \ No newline at end of file diff --git a/src/core/textures/VideoBaseTexture.js b/src/core/textures/VideoBaseTexture.js index d27bc63..d04c51d 100644 --- a/src/core/textures/VideoBaseTexture.js +++ b/src/core/textures/VideoBaseTexture.js @@ -1,5 +1,5 @@ -let BaseTexture = require('./BaseTexture'), - utils = require('../utils'); +import BaseTexture from './BaseTexture'; +import utils from '../utils'; /** * A texture of a [playing] Video. @@ -29,7 +29,8 @@ * @param source {HTMLVideoElement} Video source * @param [scaleMode=PIXI.SCALE_MODES.DEFAULT] {number} See {@link PIXI.SCALE_MODES} for possible values */ -class VideoBaseTexture extends BaseTexture { +class VideoBaseTexture extends BaseTexture +{ constructor(source, scaleMode) { if (!source) @@ -219,11 +220,8 @@ return VideoBaseTexture.fromVideo(video, scaleMode); } - } -module.exports = VideoBaseTexture; - VideoBaseTexture.fromUrls = VideoBaseTexture.fromUrl; function createSource(path, type) @@ -240,3 +238,5 @@ return source; } + +export default VideoBaseTexture; \ No newline at end of file diff --git a/src/core/ticker/Ticker.js b/src/core/ticker/Ticker.js index 14a3453..4319c4e 100644 --- a/src/core/ticker/Ticker.js +++ b/src/core/ticker/Ticker.js @@ -1,7 +1,8 @@ -let CONST = require('../const'), - EventEmitter = require('eventemitter3'), - // Internal event used by composed emitter - TICK = 'tick'; +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; + +// Internal event used by composed emitter +const TICK = 'tick'; /** * A Ticker class that runs an update loop that other objects listen to. @@ -13,7 +14,8 @@ * @class * @memberof PIXI.ticker */ -class Ticker { +class Ticker +{ constructor() { /** @@ -104,6 +106,9 @@ * @default false */ this.started = false; + + // Bind tick + this._tick = this._tick.bind(this); } /** @@ -116,20 +121,18 @@ * * @private */ - _tick(time) { + _tick(time) + { + this._requestId = null; - let _this = this; - - _this._requestId = null; - - if (_this.started) + if (this.started) { // Invoke listeners now - _this.update(time); + this.update(time); // Listener side effects may have modified ticker state. - if (_this.started && _this._requestId === null && _this._emitter.listeners(TICK, true)) + if (this.started && this._requestId === null && this._emitter.listeners(TICK, true)) { - _this._requestId = requestAnimationFrame(_this._tick); + this._requestId = requestAnimationFrame(this._tick); } } } @@ -329,9 +332,6 @@ this.lastTime = currentTime; } -} - -Object.defineProperties(Ticker.prototype, { /** * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. @@ -342,12 +342,10 @@ * @memberof PIXI.ticker.Ticker# * @readonly */ - FPS: { - get: function() - { - return 1000 / this.elapsedMS; - } - }, + get FPS() + { + return 1000 / this.elapsedMS; + } /** * Manages the maximum amount of milliseconds allowed to @@ -360,18 +358,16 @@ * @memberof PIXI.ticker.Ticker# * @default 10 */ - minFPS: { - get: function() - { - return 1000 / this._maxElapsedMS; - }, - set: function(fps) - { - // Clamp: 0 to TARGET_FPMS - let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); - this._maxElapsedMS = 1 / minFPMS; - } + get minFPS() + { + return 1000 / this._maxElapsedMS; } -}); + set minFPS(fps) + { + // Clamp: 0 to TARGET_FPMS + let minFPMS = Math.min(Math.max(0, fps) / 1000, CONST.TARGET_FPMS); + this._maxElapsedMS = 1 / minFPMS; + } +} -module.exports = Ticker; +export default Ticker; \ No newline at end of file diff --git a/src/core/ticker/index.js b/src/core/ticker/index.js index f3c0440..85f7b08 100644 --- a/src/core/ticker/index.js +++ b/src/core/ticker/index.js @@ -1,4 +1,4 @@ -let Ticker = require('./Ticker'); +import Ticker from './Ticker'; /** * The shared ticker instance used by {@link PIXI.extras.MovieClip}. @@ -42,13 +42,13 @@ * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker */ -let shared = new Ticker(); +const shared = new Ticker(); shared.autoStart = true; /** * @namespace PIXI.ticker */ -module.exports = { - shared: shared, - Ticker: Ticker -}; +export default { + shared, + Ticker +}; \ No newline at end of file diff --git a/src/core/utils/createIndicesForQuads.js b/src/core/utils/createIndicesForQuads.js index bc42402..e352129 100644 --- a/src/core/utils/createIndicesForQuads.js +++ b/src/core/utils/createIndicesForQuads.js @@ -5,7 +5,7 @@ * @param size {number} Number of quads * @return {Uint16Array} indices */ -let createIndicesForQuads = function (size) +const createIndicesForQuads = function (size) { // the total number of indices in our array, there are 6 points per quad. @@ -27,4 +27,4 @@ return indices; }; -module.exports = createIndicesForQuads; +export default createIndicesForQuads; diff --git a/src/core/utils/determineCrossOrigin.js b/src/core/utils/determineCrossOrigin.js index 907b1f1..c4ca354 100644 --- a/src/core/utils/determineCrossOrigin.js +++ b/src/core/utils/determineCrossOrigin.js @@ -1,5 +1,6 @@ +import _url from 'url'; + let tempAnchor; -let _url = require('url'); /** * Sets the `crossOrigin` property for this resource based on if the url @@ -11,7 +12,7 @@ * @param loc [location=window.location] {object} The location object to test against. * @return {string} The crossOrigin value to use (or empty string for none). */ -let determineCrossOrigin = function (url, loc) { +const determineCrossOrigin = function (url, loc) { // data: and javascript: urls are considered same-origin if (url.indexOf('data:') === 0) { return ''; @@ -40,4 +41,4 @@ return ''; }; -module.exports = determineCrossOrigin; +export default determineCrossOrigin; diff --git a/src/core/utils/index.js b/src/core/utils/index.js index 50a0e60..f6ebb8d 100644 --- a/src/core/utils/index.js +++ b/src/core/utils/index.js @@ -1,14 +1,16 @@ -let CONST = require('../const'); +import CONST from '../const'; +import EventEmitter from 'eventemitter3'; +import pluginTarget from './pluginTarget'; /** * @namespace PIXI.utils */ -let utils = module.exports = { +const utils = { _uid: 0, _saidHello: false, - EventEmitter: require('eventemitter3'), - pluginTarget: require('./pluginTarget'), + EventEmitter, + pluginTarget, /** * Gets the next unique identifier @@ -225,3 +227,5 @@ */ BaseTextureCache: {} }; + +export default utils; diff --git a/src/core/utils/maxRecommendedTextures.js b/src/core/utils/maxRecommendedTextures.js index c75e339..cf0d726 100644 --- a/src/core/utils/maxRecommendedTextures.js +++ b/src/core/utils/maxRecommendedTextures.js @@ -1,10 +1,7 @@ +import Device from 'ismobilejs'; - -let Device = require('ismobilejs'); - -let maxRecommendedTextures = function(max) +const maxRecommendedTextures = function(max) { - if(Device.tablet || Device.phone) { // check if the res is iphone 6 or higher.. @@ -17,4 +14,4 @@ } }; -module.exports = maxRecommendedTextures; \ No newline at end of file +export default maxRecommendedTextures; \ No newline at end of file diff --git a/src/core/utils/pluginTarget.js b/src/core/utils/pluginTarget.js index 1ee40db..ec0375f 100644 --- a/src/core/utils/pluginTarget.js +++ b/src/core/utils/pluginTarget.js @@ -55,7 +55,7 @@ } -module.exports = { +export default { /** * Mixes in the properties of the pluginTarget into another object * @@ -65,4 +65,4 @@ { pluginTarget(obj); } -}; +}; \ No newline at end of file diff --git a/src/deprecation.js b/src/deprecation.js index b058664..5d5357f 100644 --- a/src/deprecation.js +++ b/src/deprecation.js @@ -1,9 +1,9 @@ /*global console */ -let core = require('./core'), - mesh = require('./mesh'), - particles = require('./particles'), - extras = require('./extras'), - filters = require('./filters'); +import core from './core'; +import mesh from './mesh'; +import particles from './particles'; +import extras from './extras'; +import filters from './filters'; // @if DEBUG // provide method to give a stack track for warnings diff --git a/src/extract/canvas/CanvasExtract.js b/src/extract/canvas/CanvasExtract.js index cd6a094..0b88e4e 100644 --- a/src/extract/canvas/CanvasExtract.js +++ b/src/extract/canvas/CanvasExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasExtract { +class CanvasExtract +{ constructor(renderer) { this.renderer = renderer; @@ -143,9 +144,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = CanvasExtract; - core.CanvasRenderer.registerPlugin('extract', CanvasExtract); + +export default CanvasExtract; diff --git a/src/extract/index.js b/src/extract/index.js index fd901d7..f9fbbea 100644 --- a/src/extract/index.js +++ b/src/extract/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLExtract'; +import canvas from './canvas/CanvasExtract'; -module.exports = { - webGL: require('./webgl/WebGLExtract'), - canvas: require('./canvas/CanvasExtract') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/extract/webgl/WebGLExtract.js b/src/extract/webgl/WebGLExtract.js index 1fb479c..f892545 100644 --- a/src/extract/webgl/WebGLExtract.js +++ b/src/extract/webgl/WebGLExtract.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - tempRect = new core.Rectangle(); +import core from '../../core'; +const tempRect = new core.Rectangle(); /** * The extract manager provides functionality to export content from the renderers @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLExtract { +class WebGLExtract +{ constructor(renderer) { this.renderer = renderer; @@ -188,9 +189,8 @@ this.renderer.extract = null; this.renderer = null; } - } -module.exports = WebGLExtract; - core.WebGLRenderer.registerPlugin('extract', WebGLExtract); + +export default WebGLExtract; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index b13b895..6428502 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ -let core = require('../core'), - ObservablePoint = require('../core/math/ObservablePoint'); +import core from '../core'; +import ObservablePoint from '../core/math/ObservablePoint'; /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -28,7 +28,8 @@ * single line text * @param [style.tint=0xFFFFFF] {number} The tint color */ -class BitmapText extends core.Container { +class BitmapText extends core.Container +{ constructor(text, style) { super(); @@ -310,29 +311,22 @@ this.dirty = true; } -} - -module.exports = BitmapText; - -Object.defineProperties(BitmapText.prototype, { /** * The tint of the BitmapText object * * @member {number} * @memberof PIXI.extras.BitmapText# */ - tint: { - get: function () - { - return this._font.tint; - }, - set: function (value) - { - this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; + get tint() + { + return this._font.tint; + } + set tint(value) + { + this._font.tint = (typeof value === 'number' && value >= 0) ? value : 0xFFFFFF; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The alignment of the BitmapText object @@ -341,18 +335,16 @@ * @default 'left' * @memberof PIXI.extras.BitmapText# */ - align: { - get: function () - { - return this._font.align; - }, - set: function (value) - { - this._font.align = value || 'left'; + get align() + { + return this._font.align; + } + set align(value) + { + this._font.align = value || 'left'; - this.dirty = true; - } - }, + this.dirty = true; + } /** * The anchor sets the origin point of the text. @@ -363,19 +355,17 @@ * @member {PIXI.Point | number} * @memberof PIXI.extras.BitmapText# */ - anchor: { - get : function() { - return this._anchor; - }, - set: function(value) { - if (typeof value === 'number'){ - this._anchor.set(value); - } - else { - this._anchor.copy(value); - } + get anchor() { + return this._anchor; + } + set anchor(value) { + if (typeof value === 'number'){ + this._anchor.set(value); } - }, + else { + this._anchor.copy(value); + } + } /** * The font descriptor of the BitmapText object @@ -383,31 +373,29 @@ * @member {string|object} * @memberof PIXI.extras.BitmapText# */ - font: { - get: function () - { - return this._font; - }, - set: function (value) - { - if (!value) { - return; - } - - if (typeof value === 'string') { - value = value.split(' '); - - this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); - this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; - } - else { - this._font.name = value.name; - this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); - } - - this.dirty = true; + get font() + { + return this._font; + } + set font(value) + { + if (!value) { + return; } - }, + + if (typeof value === 'string') { + value = value.split(' '); + + this._font.name = value.length === 1 ? value[0] : value.slice(1).join(' '); + this._font.size = value.length >= 2 ? parseInt(value[0], 10) : BitmapText.fonts[this._font.name].size; + } + else { + this._font.name = value.name; + this._font.size = typeof value.size === 'number' ? value.size : parseInt(value.size, 10); + } + + this.dirty = true; + } /** * The text of the BitmapText object @@ -415,22 +403,22 @@ * @member {string} * @memberof PIXI.extras.BitmapText# */ - text: { - get: function () - { - return this._text; - }, - set: function (value) - { - value = value.toString() || ' '; - if (this._text === value) - { - return; - } - this._text = value; - this.dirty = true; - } + get text() + { + return this._text; } -}); + set text(value) + { + value = value.toString() || ' '; + if (this._text === value) + { + return; + } + this._text = value; + this.dirty = true; + } +} -BitmapText.fonts = {}; +export default BitmapText; + +BitmapText.fonts = {}; \ No newline at end of file diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index 7724a94..8827f00 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * @typedef FrameObject @@ -29,7 +29,8 @@ * @memberof PIXI.extras * @param textures {PIXI.Texture[]|FrameObject[]} an array of {@link PIXI.Texture} or frame objects that make up the animation */ -class MovieClip extends core.Sprite { +class MovieClip extends core.Sprite +{ constructor(textures) { super(textures[0] instanceof core.Texture ? textures[0] : textures[0].texture); @@ -252,11 +253,6 @@ return new MovieClip(textures); } -} - -module.exports = MovieClip; - -Object.defineProperties(MovieClip.prototype, { /** * totalFrames is the total number of frames in the MovieClip. This is the same as number of textures * assigned to the MovieClip. @@ -266,12 +262,10 @@ * @default 0 * @readonly */ - totalFrames: { - get: function() - { - return this._textures.length; - } - }, + get totalFrames() + { + return this._textures.length; + } /** * The array of textures used for this MovieClip @@ -280,30 +274,28 @@ * @memberof PIXI.extras.MovieClip# * */ - textures: { - get: function () + get textures() + { + return this._textures; + } + set textures(value) + { + if(value[0] instanceof core.Texture) { - return this._textures; - }, - set: function (value) + this._textures = value; + this._durations = null; + } + else { - if(value[0] instanceof core.Texture) + this._textures = []; + this._durations = []; + for(let i = 0; i < value.length; i++) { - this._textures = value; - this._durations = null; - } - else - { - this._textures = []; - this._durations = []; - for(let i = 0; i < value.length; i++) - { - this._textures.push(value[i].texture); - this._durations.push(value[i].time); - } + this._textures.push(value[i].texture); + this._durations.push(value[i].time); } } - }, + } /** * The MovieClips current frame index @@ -312,16 +304,15 @@ * @memberof PIXI.extras.MovieClip# * @readonly */ - currentFrame: { - get: function () + get currentFrame() + { + let currentFrame = Math.floor(this._currentTime) % this._textures.length; + if (currentFrame < 0) { - let currentFrame = Math.floor(this._currentTime) % this._textures.length; - if (currentFrame < 0) - { - currentFrame += this._textures.length; - } - return currentFrame; + currentFrame += this._textures.length; } + return currentFrame; } +} -}); +export default MovieClip; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index 3e04c71..b02da6c 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -1,9 +1,10 @@ -let core = require('../core'), - tempPoint = new core.Point(), - Texture = require('../core/textures/Texture'), - CanvasTinter = require('../core/sprites/canvas/CanvasTinter'), - TilingShader = require('./webgl/TilingShader'), - tempArray = new Float32Array(4); +import core from '../core'; +import Texture from '../core/textures/Texture'; +import CanvasTinter from '../core/sprites/canvas/CanvasTinter'; +import TilingShader from './webgl/TilingShader'; + +const tempArray = new Float32Array(4); +const tempPoint = new core.Point(); /** * A tiling sprite is a fast way of rendering a tiling image * @@ -14,7 +15,8 @@ * @param width {number} the width of the tiling sprite * @param height {number} the height of the tiling sprite */ -class TilingSprite extends core.Sprite { +class TilingSprite extends core.Sprite +{ constructor(texture, width, height) { super(texture); @@ -414,27 +416,20 @@ return new TilingSprite(core.Texture.fromImage(imageId, crossorigin, scaleMode),width,height); } -} - -module.exports = TilingSprite; - -Object.defineProperties(TilingSprite.prototype, { /** * The width of the sprite, setting this will actually modify the scale to achieve the value set * * @member {number} * @memberof PIXI.extras.TilingSprite# */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + } /** * The height of the TilingSprite, setting this will actually modify the scale to achieve the value set @@ -442,14 +437,14 @@ * @member {number} * @memberof PIXI.extras.TilingSprite# */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - } + get height() + { + return this._height; } -}); + set height(value) + { + this._height = value; + } +} + +export default TilingSprite; \ No newline at end of file diff --git a/src/extras/cacheAsBitmap.js b/src/extras/cacheAsBitmap.js index 4b47465..403e4f6 100644 --- a/src/extras/cacheAsBitmap.js +++ b/src/extras/cacheAsBitmap.js @@ -1,6 +1,7 @@ -let core = require('../core'), - DisplayObject = core.DisplayObject, - _tempMatrix = new core.Matrix(); +import core from '../core'; + +const DisplayObject = core.DisplayObject; +const _tempMatrix = new core.Matrix(); DisplayObject.prototype._cacheAsBitmap = false; DisplayObject.prototype._cacheData = false; diff --git a/src/extras/getChildByName.js b/src/extras/getChildByName.js index 70ad352..8cce4fc 100644 --- a/src/extras/getChildByName.js +++ b/src/extras/getChildByName.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The instance name of the object. diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js index 47cfa78..b6c20f0 100644 --- a/src/extras/getGlobalPosition.js +++ b/src/extras/getGlobalPosition.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Returns the global position of the displayObject @@ -25,4 +25,4 @@ } return point; -}; +}; \ No newline at end of file diff --git a/src/extras/index.js b/src/extras/index.js index 07ed8bc..af2e89e 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -1,9 +1,6 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import MovieClip from './MovieClip'; +import TilingSprite from './TilingSprite'; +import BitmapText from './BitmapText'; require('./cacheAsBitmap'); require('./getChildByName'); @@ -12,8 +9,8 @@ /** * @namespace PIXI.extras */ -module.exports = { - MovieClip: require('./MovieClip'), - TilingSprite: require('./TilingSprite'), - BitmapText: require('./BitmapText') -}; +export default { + MovieClip, + TilingSprite, + BitmapText +}; \ No newline at end of file diff --git a/src/extras/webgl/TilingShader.js b/src/extras/webgl/TilingShader.js index 9ffb3ea..874b8b6 100644 --- a/src/extras/webgl/TilingShader.js +++ b/src/extras/webgl/TilingShader.js @@ -1,5 +1,5 @@ -let Shader = require('../../core/Shader'); -let glslify = require('glslify'); +import Shader from '../../core/Shader'; +const glslify = require('glslify'); /** * @class @@ -7,7 +7,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} The WebGL shader manager this shader works for. */ -class TilingShader extends Shader { +class TilingShader extends Shader +{ constructor(gl) { super( @@ -18,4 +19,4 @@ } } -module.exports = TilingShader; +export default TilingShader; diff --git a/src/filters/blur/BlurFilter.js b/src/filters/blur/BlurFilter.js index 6517451..659c0e1 100644 --- a/src/filters/blur/BlurFilter.js +++ b/src/filters/blur/BlurFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - BlurXFilter = require('./BlurXFilter'), - BlurYFilter = require('./BlurYFilter'); +import core from '../../core'; +import BlurXFilter from './BlurXFilter'; +import BlurYFilter from './BlurYFilter'; /** * The BlurFilter applies a Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurFilter extends core.Filter { +class BlurFilter extends core.Filter +{ constructor(strength, quality, resolution) { super(); @@ -36,11 +37,6 @@ filterManager.returnRenderTarget(renderTarget); } -} - -module.exports = BlurFilter; - -Object.defineProperties(BlurFilter.prototype, { /** * Sets the strength of both the blurX and blurY properties simultaneously * @@ -48,17 +44,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blur: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blur() + { + return this.blurXFilter.blur; + } + set blur(value) + { + this.blurXFilter.blur = this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the number of passes for blur. More passes means higher quaility bluring. @@ -67,17 +61,14 @@ * @memberof PIXI.filters.BlurYFilter# * @default 1 */ - quality: { - get: function () - { - return this.blurXFilter.quality; - }, - set: function (value) - { - - this.blurXFilter.quality = this.blurYFilter.quality = value; - } - }, + get quality() + { + return this.blurXFilter.quality; + } + set quality(value) + { + this.blurXFilter.quality = this.blurYFilter.quality = value; + } /** * Sets the strength of the blurX property @@ -86,17 +77,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurX: { - get: function () - { - return this.blurXFilter.blur; - }, - set: function (value) - { - this.blurXFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } - }, + get blurX() + { + return this.blurXFilter.blur; + } + set blurX(value) + { + this.blurXFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } /** * Sets the strength of the blurY property @@ -105,15 +94,15 @@ * @memberOf PIXI.filters.BlurFilter# * @default 2 */ - blurY: { - get: function () - { - return this.blurYFilter.blur; - }, - set: function (value) - { - this.blurYFilter.blur = value; - this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; - } + get blurY() + { + return this.blurYFilter.blur; } -}); + set blurY(value) + { + this.blurYFilter.blur = value; + this.padding = Math.max( Math.abs(this.blurYFilter.strength), Math.abs(this.blurYFilter.strength)) * 2; + } +} + +export default BlurFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurXFilter.js b/src/filters/blur/BlurXFilter.js index 8868aad..53768cf 100644 --- a/src/filters/blur/BlurXFilter.js +++ b/src/filters/blur/BlurXFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurXFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurXFilter extends core.Filter { +class BlurXFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, true); @@ -78,11 +79,6 @@ } } -} - -module.exports = BlurXFilter; - -Object.defineProperties(BlurXFilter.prototype, { /** * Sets the strength of both the blur. * @@ -90,18 +86,16 @@ * @memberof PIXI.filters.BlurXFilter# * @default 16 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, - + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } + /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. * @@ -109,15 +103,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurXFilter; \ No newline at end of file diff --git a/src/filters/blur/BlurYFilter.js b/src/filters/blur/BlurYFilter.js index 578de88..b5dcc84 100644 --- a/src/filters/blur/BlurYFilter.js +++ b/src/filters/blur/BlurYFilter.js @@ -1,7 +1,7 @@ -let core = require('../../core'); -let generateBlurVertSource = require('./generateBlurVertSource'); -let generateBlurFragSource = require('./generateBlurFragSource'); -let getMaxBlurKernelSize = require('./getMaxBlurKernelSize'); +import core from '../../core'; +import generateBlurVertSource from './generateBlurVertSource'; +import generateBlurFragSource from './generateBlurFragSource'; +import getMaxBlurKernelSize from './getMaxBlurKernelSize'; /** * The BlurYFilter applies a horizontal Gaussian blur to an object. @@ -10,7 +10,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class BlurYFilter extends core.Filter { +class BlurYFilter extends core.Filter +{ constructor(strength, quality, resolution) { let vertSrc = generateBlurVertSource(5, false); @@ -76,11 +77,6 @@ } } -} - -module.exports = BlurYFilter; - -Object.defineProperties(BlurYFilter.prototype, { /** * Sets the strength of both the blur. * @@ -88,17 +84,15 @@ * @memberof PIXI.filters.BlurYFilter# * @default 2 */ - blur: { - get: function () - { - return this.strength; - }, - set: function (value) - { - this.padding = Math.abs(value) * 2; - this.strength = value; - } - }, + get blur() + { + return this.strength; + } + set blur(value) + { + this.padding = Math.abs(value) * 2; + this.strength = value; + } /** * Sets the quality of the blur by modifying the number of passes. More passes means higher quaility bluring but the lower the performance. @@ -107,15 +101,15 @@ * @memberof PIXI.filters.BlurXFilter# * @default 4 */ - quality: { - get: function () - { - return this._quality; - }, - set: function (value) - { - this._quality = value; - this.passes = value; - } + get quality() + { + return this._quality; } -}); + set quality(value) + { + this._quality = value; + this.passes = value; + } +} + +export default BlurYFilter; diff --git a/src/filters/blur/generateBlurFragSource.js b/src/filters/blur/generateBlurFragSource.js index 8088068..8b77826 100644 --- a/src/filters/blur/generateBlurFragSource.js +++ b/src/filters/blur/generateBlurFragSource.js @@ -1,4 +1,4 @@ -let GAUSSIAN_VALUES = { +const GAUSSIAN_VALUES = { 5:[0.153388, 0.221461, 0.250301], 7:[0.071303, 0.131514, 0.189879, 0.214607], 9:[0.028532, 0.067234, 0.124009, 0.179044, 0.20236], @@ -7,7 +7,7 @@ 15:[0.000489, 0.002403, 0.009246, 0.02784, 0.065602, 0.120999, 0.174697, 0.197448] }; -let fragTemplate = [ +const fragTemplate = [ 'varying vec2 vBlurTexCoords[%size%];', 'uniform sampler2D uSampler;', @@ -19,7 +19,7 @@ ].join('\n'); -let generateFragBlurSource = function(kernelSize) +const generateFragBlurSource = function(kernelSize) { let kernel = GAUSSIAN_VALUES[kernelSize]; let halfLength = kernel.length; @@ -55,6 +55,4 @@ return fragSource; }; - - -module.exports = generateFragBlurSource; +export default generateFragBlurSource; \ No newline at end of file diff --git a/src/filters/blur/generateBlurVertSource.js b/src/filters/blur/generateBlurVertSource.js index 66a1db4..16c64a4 100644 --- a/src/filters/blur/generateBlurVertSource.js +++ b/src/filters/blur/generateBlurVertSource.js @@ -1,5 +1,4 @@ - -let vertTemplate = [ +const vertTemplate = [ 'attribute vec2 aVertexPosition;', 'attribute vec2 aTextureCoord;', @@ -15,7 +14,7 @@ '}' ].join('\n'); -let generateVertBlurSource = function(kernelSize, x) +const generateVertBlurSource = function(kernelSize, x) { let halfLength = Math.ceil(kernelSize/2); @@ -59,6 +58,4 @@ return vertSource; }; - - -module.exports = generateVertBlurSource; +export default generateVertBlurSource; \ No newline at end of file diff --git a/src/filters/blur/getMaxBlurKernelSize.js b/src/filters/blur/getMaxBlurKernelSize.js index 3b105db..641e343 100644 --- a/src/filters/blur/getMaxBlurKernelSize.js +++ b/src/filters/blur/getMaxBlurKernelSize.js @@ -1,8 +1,6 @@ - - -let getMaxKernelSize = function(gl) +const getMaxKernelSize = function(gl) { - let maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); + const maxVaryings = ( gl.getParameter(gl.MAX_VARYING_VECTORS) ); let kernelSize = 15; while(kernelSize > maxVaryings) @@ -13,4 +11,4 @@ return kernelSize; }; -module.exports = getMaxKernelSize; +export default getMaxKernelSize; \ No newline at end of file diff --git a/src/filters/colormatrix/ColorMatrixFilter.js b/src/filters/colormatrix/ColorMatrixFilter.js index 86676e2..34fb962 100644 --- a/src/filters/colormatrix/ColorMatrixFilter.js +++ b/src/filters/colormatrix/ColorMatrixFilter.js @@ -1,6 +1,5 @@ -let core = require('../../core'); -// @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The ColorMatrixFilter class lets you apply a 5x4 matrix transformation on the RGBA @@ -17,7 +16,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class ColorMatrixFilter extends core.Filter { +class ColorMatrixFilter extends core.Filter +{ constructor() { super( @@ -32,8 +32,6 @@ 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0]; - - } @@ -528,14 +526,6 @@ this._loadMatrix(matrix, false); } -} - -//Americanized alias -ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; - -module.exports = ColorMatrixFilter; - -Object.defineProperties(ColorMatrixFilter.prototype, { /** * Sets the matrix of the color matrix filter * @@ -543,14 +533,17 @@ * @memberof PIXI.filters.ColorMatrixFilter# * @default [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0] */ - matrix: { - get: function () - { - return this.uniforms.m; - }, - set: function (value) - { - this.uniforms.m = value; - } + get matrix() + { + return this.uniforms.m; } -}); + set matrix(value) + { + this.uniforms.m = value; + } +} + +//Americanized alias +ColorMatrixFilter.prototype.grayscale = ColorMatrixFilter.prototype.greyscale; + +export default ColorMatrixFilter; \ No newline at end of file diff --git a/src/filters/displacement/DisplacementFilter.js b/src/filters/displacement/DisplacementFilter.js index 6c88b65..d222540 100644 --- a/src/filters/displacement/DisplacementFilter.js +++ b/src/filters/displacement/DisplacementFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * The DisplacementFilter class uses the pixel values from the specified texture (called the displacement map) to perform a displacement of an object. @@ -12,7 +12,8 @@ * @param sprite {PIXI.Sprite} The sprite used for the displacement map. (make sure its added to the scene!) * @param scale {number} The scale of the displacement */ -class DisplacementFilter extends core.Filter { +class DisplacementFilter extends core.Filter +{ constructor(sprite, scale) { let maskMatrix = new core.Matrix(); @@ -54,26 +55,20 @@ filterManager.applyFilter(this, input, output); } -} - -module.exports = DisplacementFilter; - -Object.defineProperties(DisplacementFilter.prototype, { /** * The texture used for the displacement map. Must be power of 2 sized texture. * * @member {PIXI.Texture} * @memberof PIXI.filters.DisplacementFilter# */ - map: { - get: function () - { - return this.uniforms.mapSampler; - }, - set: function (value) - { - this.uniforms.mapSampler = value; - - } + get map() + { + return this.uniforms.mapSampler; } -}); + set map(value) + { + this.uniforms.mapSampler = value; + } +} + +export default DisplacementFilter; \ No newline at end of file diff --git a/src/filters/fxaa/FXAAFilter.js b/src/filters/fxaa/FXAAFilter.js index d9a7c67..0c9c8a2 100644 --- a/src/filters/fxaa/FXAAFilter.js +++ b/src/filters/fxaa/FXAAFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @@ -14,7 +14,8 @@ * @memberof PIXI * */ -class FXAAFilter extends core.Filter { +class FXAAFilter extends core.Filter +{ constructor() { //TODO - needs work @@ -28,4 +29,4 @@ } } -module.exports = FXAAFilter; +export default FXAAFilter; diff --git a/src/filters/index.js b/src/filters/index.js index 54c1a3b..596a8c4 100644 --- a/src/filters/index.js +++ b/src/filters/index.js @@ -1,20 +1,22 @@ -/** - * @file Main export of the PIXI filters library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import FXAAFilter from './fxaa/FXAAFilter'; +import NoiseFilter from './noise/NoiseFilter'; +import DisplacementFilter from './displacement/DisplacementFilter'; +import BlurFilter from './blur/BlurFilter'; +import BlurXFilter from './blur/BlurXFilter'; +import BlurYFilter from './blur/BlurYFilter'; +import ColorMatrixFilter from './colormatrix/ColorMatrixFilter'; +import VoidFilter from './void/VoidFilter'; /** * @namespace PIXI.filters */ -module.exports = { - FXAAFilter: require('./fxaa/FXAAFilter'), - NoiseFilter: require('./noise/NoiseFilter'), - DisplacementFilter: require('./displacement/DisplacementFilter'), - BlurFilter: require('./blur/BlurFilter'), - BlurXFilter: require('./blur/BlurXFilter'), - BlurYFilter: require('./blur/BlurYFilter'), - ColorMatrixFilter: require('./colormatrix/ColorMatrixFilter'), - VoidFilter: require('./void/VoidFilter') +export default { + FXAAFilter, + NoiseFilter, + DisplacementFilter, + BlurFilter, + BlurXFilter, + BlurYFilter, + ColorMatrixFilter, + VoidFilter }; diff --git a/src/filters/noise/NoiseFilter.js b/src/filters/noise/NoiseFilter.js index 10c3280..a7b361c 100644 --- a/src/filters/noise/NoiseFilter.js +++ b/src/filters/noise/NoiseFilter.js @@ -1,5 +1,5 @@ -let core = require('../../core'); -let glslify = require('glslify'); +import core from '../../core'; +const glslify = require('glslify'); /** * @author Vico @vicocotea @@ -13,7 +13,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class NoiseFilter extends core.Filter { +class NoiseFilter extends core.Filter +{ constructor() { super( @@ -25,11 +26,7 @@ this.noise = 0.5; } -} -module.exports = NoiseFilter; - -Object.defineProperties(NoiseFilter.prototype, { /** * The amount of noise to apply. * @@ -37,14 +34,14 @@ * @memberof PIXI.filters.NoiseFilter# * @default 0.5 */ - noise: { - get: function () - { - return this.uniforms.noise; - }, - set: function (value) - { - this.uniforms.noise = value; - } + get noise() + { + return this.uniforms.noise; } -}); + set noise(value) + { + this.uniforms.noise = value; + } +} + +export default NoiseFilter; \ No newline at end of file diff --git a/src/filters/void/VoidFilter.js b/src/filters/void/VoidFilter.js index f201210..c19b6d4 100644 --- a/src/filters/void/VoidFilter.js +++ b/src/filters/void/VoidFilter.js @@ -1,6 +1,6 @@ -let core = require('../../core'); +import core from '../../core'; // @see https://github.com/substack/brfs/issues/25 -let glslify = require('glslify'); +const glslify = require('glslify'); /** * Does nothing. Very handy. @@ -9,7 +9,8 @@ * @extends PIXI.Filter * @memberof PIXI.filters */ -class VoidFilter extends core.Filter { +class VoidFilter extends core.Filter +{ constructor() { super( @@ -23,4 +24,4 @@ } } -module.exports = VoidFilter; +export default VoidFilter; \ No newline at end of file diff --git a/src/index.js b/src/index.js index bd84133..fe53c65 100644 --- a/src/index.js +++ b/src/index.js @@ -1,20 +1,17 @@ +import extras from './extras'; +import filters from './filters'; +import interaction from './interaction'; +import loaders from './loaders'; +import mesh from './mesh'; +import particles from './particles'; +import accessibility from './accessibility'; +import extract from './extract'; +import prepare from './prepare'; +import core from './core'; + // run the polyfills require('./polyfill'); -let core = module.exports = require('./core'); - -// add core plugins. -core.extras = require('./extras'); -core.filters = require('./filters'); -core.interaction = require('./interaction'); -core.loaders = require('./loaders'); -core.mesh = require('./mesh'); -core.particles = require('./particles'); -core.accessibility = require('./accessibility'); -core.extract = require('./extract'); -core.prepare = require('./prepare'); - -// export a premade loader instance /** * A premade instance of the loader that can be used to loader resources. * @@ -22,10 +19,24 @@ * @memberof PIXI * @property {PIXI.loaders.Loader} */ -core.loader = new core.loaders.Loader(); +const loader = new loaders.Loader(); -// mixin the deprecation features. -Object.assign(core, require('./deprecation')); +// add core plugins +module.exports = Object.assign(core, { + accessibility, + extract, + extras, + filters, + interaction, + loaders, + loader, + mesh, + particles, + prepare +}); + +// Mixin the deprecations +require('./deprecation'); // Always export pixi globally. -global.PIXI = core; +global.PIXI = core; \ No newline at end of file diff --git a/src/interaction/InteractionData.js b/src/interaction/InteractionData.js index 57f52b5..a6edeac 100644 --- a/src/interaction/InteractionData.js +++ b/src/interaction/InteractionData.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * Holds all information related to an Interaction event @@ -6,7 +6,8 @@ * @class * @memberof PIXI.interaction */ -class InteractionData { +class InteractionData +{ constructor() { /** @@ -43,7 +44,6 @@ { return displayObject.worldTransform.applyInverse(globalPos || this.global, point); } - } -module.exports = InteractionData; +export default InteractionData; diff --git a/src/interaction/InteractionManager.js b/src/interaction/InteractionManager.js index 44bd81b..a94415c 100644 --- a/src/interaction/InteractionManager.js +++ b/src/interaction/InteractionManager.js @@ -1,6 +1,6 @@ -let core = require('../core'), - InteractionData = require('./InteractionData'), - EventEmitter = require('eventemitter3'); +import core from '../core'; +import InteractionData from './InteractionData'; +import EventEmitter from 'eventemitter3'; // Mix interactiveTarget into core.DisplayObject.prototype Object.assign( @@ -21,7 +21,8 @@ * @param [options.autoPreventDefault=true] {boolean} Should the manager automatically prevent default browser actions. * @param [options.interactionFrequency=10] {number} Frequency increases the interaction events will be checked. */ -class InteractionManager extends EventEmitter { +class InteractionManager extends EventEmitter +{ constructor(renderer, options) { super(); @@ -1103,10 +1104,9 @@ this._tempPoint = null; } - } -module.exports = InteractionManager; - core.WebGLRenderer.registerPlugin('interaction', InteractionManager); core.CanvasRenderer.registerPlugin('interaction', InteractionManager); + +export default InteractionManager; diff --git a/src/interaction/index.js b/src/interaction/index.js index df2b6ab..2de941b 100644 --- a/src/interaction/index.js +++ b/src/interaction/index.js @@ -1,15 +1,12 @@ -/** - * @file Main export of the PIXI interactions library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import InteractionData from './InteractionData'; +import InteractionManager from './InteractionManager'; +import interactiveTarget from './interactiveTarget'; /** * @namespace PIXI.interaction */ -module.exports = { - InteractionData: require('./InteractionData'), - InteractionManager: require('./InteractionManager'), - interactiveTarget: require('./interactiveTarget') +export default { + InteractionData, + InteractionManager, + interactiveTarget }; diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index f6f262e..ea46902 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -12,7 +12,7 @@ * PIXI.interaction.interactiveTarget * ); */ -let interactiveTarget = { +const interactiveTarget = { /** * Determines if the displayObject be clicked/touched * @@ -85,4 +85,4 @@ _touchDown: false }; -module.exports = interactiveTarget; +export default interactiveTarget; diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index ff860c6..e32ee4c 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,8 +1,7 @@ -let Resource = require('resource-loader').Resource, - core = require('../core'), - extras = require('../extras'), - path = require('path'); - +import {Resource} from 'resource-loader'; +import core from '../core'; +import extras from '../extras'; +import path from 'path'; function parse(resource, texture) { let data = {}; @@ -60,7 +59,7 @@ } -module.exports = function () +export default function () { return function (resource, next) { @@ -122,4 +121,4 @@ }); } }; -}; +} diff --git a/src/loaders/index.js b/src/loaders/index.js index eb42cde..1b454fe 100644 --- a/src/loaders/index.js +++ b/src/loaders/index.js @@ -1,19 +1,16 @@ -/** - * @file Main export of the PIXI loaders library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Loader from './loader'; +import bitmapFontParser from './bitmapFontParser'; +import spritesheetParser from './spritesheetParser'; +import textureParser from './textureParser'; +import {Resource} from 'resource-loader'; /** * @namespace PIXI.loaders */ -module.exports = { - Loader: require('./loader'), - - // parsers - bitmapFontParser: require('./bitmapFontParser'), - spritesheetParser: require('./spritesheetParser'), - textureParser: require('./textureParser'), - Resource: require('resource-loader').Resource -}; +export default { + Loader, + bitmapFontParser, + spritesheetParser, + textureParser, + Resource +}; \ No newline at end of file diff --git a/src/loaders/loader.js b/src/loaders/loader.js index 2247c23..4d1d709 100644 --- a/src/loaders/loader.js +++ b/src/loaders/loader.js @@ -1,7 +1,7 @@ -let ResourceLoader = require('resource-loader'), - textureParser = require('./textureParser'), - spritesheetParser = require('./spritesheetParser'), - bitmapFontParser = require('./bitmapFontParser'); +import ResourceLoader from 'resource-loader'; +import textureParser from './textureParser'; +import spritesheetParser from './spritesheetParser'; +import bitmapFontParser from './bitmapFontParser'; /** * @@ -26,7 +26,8 @@ * @param [concurrency=10] {number} The number of resources to load concurrently. * @see https://github.com/englercj/resource-loader */ -class Loader extends ResourceLoader { +class Loader extends ResourceLoader +{ constructor(baseUrl, concurrency) { super(baseUrl, concurrency); @@ -36,10 +37,11 @@ } } + static addPixiMiddleware(fn) { + Loader._pixiMiddleware.push(fn); + } } -module.exports = Loader; - Loader._pixiMiddleware = [ // parse any blob into more usable objects (e.g. Image) ResourceLoader.middleware.parsing.blob, @@ -51,11 +53,9 @@ bitmapFontParser ]; -Loader.addPixiMiddleware = function (fn) { - Loader._pixiMiddleware.push(fn); -}; - // Add custom extentions -let Resource = ResourceLoader.Resource; +const Resource = ResourceLoader.Resource; Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +export default Loader; diff --git a/src/loaders/spritesheetParser.js b/src/loaders/spritesheetParser.js index 64c3145..3fa8b7f 100644 --- a/src/loaders/spritesheetParser.js +++ b/src/loaders/spritesheetParser.js @@ -1,10 +1,10 @@ -let Resource = require('resource-loader').Resource, - path = require('path'), - core = require('../core'); +import {Resource} from 'resource-loader'; +import path from 'path'; +import core from '../core'; -let BATCH_SIZE = 1000; +const BATCH_SIZE = 1000; -module.exports = function () +export default function () { return function (resource, next) { @@ -121,4 +121,4 @@ } }); }; -}; +} diff --git a/src/loaders/textureParser.js b/src/loaders/textureParser.js index acb2d6b..6f771ec 100644 --- a/src/loaders/textureParser.js +++ b/src/loaders/textureParser.js @@ -1,6 +1,6 @@ -let core = require('../core'); +import core from '../core'; -module.exports = function () +export default function () { return function (resource, next) { @@ -17,4 +17,4 @@ next(); }; -}; +} diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index d343c7b..f269992 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,8 +1,9 @@ -let core = require('../core'), - glCore = require('pixi-gl-core'), - Shader = require('./webgl/MeshShader'), - tempPoint = new core.Point(), - tempPolygon = new core.Polygon(); +import core from '../core'; +import glCore from 'pixi-gl-core'; +import Shader from './webgl/MeshShader'; + +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); /** * Base mesh class @@ -15,7 +16,8 @@ * @param [indices] {Uint16Array} if you want to specify the indices * @param [drawMode] {number} the drawMode, can be any of the Mesh.DRAW_MODES consts */ -class Mesh extends core.Container { +class Mesh extends core.Container +{ constructor(texture, vertices, uvs, indices, drawMode) { super(); @@ -430,45 +432,39 @@ return false; } -} - -module.exports = Mesh; - -Object.defineProperties(Mesh.prototype, { /** * The texture that the sprite is using * * @member {PIXI.Texture} * @memberof PIXI.mesh.Mesh# */ - texture: { - get: function () + get texture() + { + return this._texture; + } + set texture(value) + { + if (this._texture === value) { - return this._texture; - }, - set: function (value) + return; + } + + this._texture = value; + + if (value) { - if (this._texture === value) + // wait for the texture to load + if (value.baseTexture.hasLoaded) { - return; + this._onTextureUpdate(); } - - this._texture = value; - - if (value) + else { - // wait for the texture to load - if (value.baseTexture.hasLoaded) - { - this._onTextureUpdate(); - } - else - { - value.once('update', this._onTextureUpdate, this); - } + value.once('update', this._onTextureUpdate, this); } } - }, + } + /** * The tint applied to the mesh. This is a hex value. A value of 0xFFFFFF will remove any tint effect. * @@ -476,15 +472,15 @@ * @memberof PIXI.mesh.Mesh# * @default 0xFFFFFF */ - tint: { - get: function() { - return core.utils.rgb2hex(this.tintRgb); - }, - set: function(value) { - this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); - } + get tint() { + return core.utils.rgb2hex(this.tintRgb); } -}); + set tint(value) { + this.tintRgb = core.utils.hex2rgb(value, this.tintRgb); + } +} + +export default Mesh; /** * Different drawing buffer modes supported diff --git a/src/mesh/NineSlicePlane.js b/src/mesh/NineSlicePlane.js index b067371..794abc2 100644 --- a/src/mesh/NineSlicePlane.js +++ b/src/mesh/NineSlicePlane.js @@ -1,6 +1,6 @@ -let DEFAULT_BORDER_SIZE= 10; +import Plane from './Plane'; -let Plane = require('./Plane'); +const DEFAULT_BORDER_SIZE = 10; /** * The NineSlicePlane allows you to stretch a texture using 9-slice scaling. The corners will remain unscaled (useful @@ -38,7 +38,8 @@ * @param {int} [bottomHeight=10] size of the bottom horizontal bar (D) * */ -class NineSlicePlane extends Plane { +class NineSlicePlane extends Plane +{ constructor(texture, leftWidth, topHeight, rightWidth, bottomHeight) { super(texture, 4, 4); @@ -196,11 +197,6 @@ context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh); } -} - -module.exports = NineSlicePlane; - -Object.defineProperties(NineSlicePlane.prototype, { /** * The width of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane * @@ -208,17 +204,16 @@ * @memberof PIXI.NineSlicePlane# * @override */ - width: { - get: function () - { - return this._width; - }, - set: function (value) - { - this._width = value; - this.updateVerticalVertices(); - } - }, + get width() + { + return this._width; + } + set width(value) + { + this._width = value; + this.updateVerticalVertices(); + } + /** * The height of the NineSlicePlane, setting this will actually modify the vertices and UV's of this plane @@ -227,96 +222,93 @@ * @memberof PIXI.NineSlicePlane# * @override */ - height: { - get: function () - { - return this._height; - }, - set: function (value) - { - this._height = value; - this.updateHorizontalVertices(); - } - }, + get height() + { + return this._height; + } + set height(value) + { + this._height = value; + this.updateHorizontalVertices(); + } + /** * The width of the left column * * @member {number} */ - leftWidth: { - get: function() - { - return this._leftWidth; - }, - set: function (value) - { - this._leftWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; - vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; - this.dirty=true; - } - }, + get leftWidth() + { + return this._leftWidth; + } + set leftWidth (value) + { + this._leftWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[2] = uvs[10] = uvs[18] = uvs[26] = this._uvw * value; + vertices[2] = vertices[10] = vertices[18] = vertices[26] = value; + this.dirty=true; + } + /** * The width of the right column * * @member {number} */ - rightWidth: { - get: function() - { - return this._rightWidth; - }, - set: function (value) - { - this._rightWidth = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; - vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; - this.dirty=true; - } - }, + get rightWidth() + { + return this._rightWidth; + } + set rightWidth(value) + { + this._rightWidth = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - this._uvw * value; + vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - value; + this.dirty=true; + } + + /** * The height of the top row * * @member {number} */ - topHeight: { - get: function() - { - return this._topHeight; - }, - set: function (value) - { - this._topHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; - vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; - this.dirty=true; - } - }, + get topHeight() + { + return this._topHeight; + } + set topHeight(value) + { + this._topHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[9] = uvs[11] = uvs[13] = uvs[15] = this._uvh * value; + vertices[9] = vertices[11] = vertices[13] = vertices[15] = value; + this.dirty=true; + } + /** * The height of the bottom row * * @member {number} */ - bottomHeight: { - get: function() - { - return this._bottomHeight; - }, - set: function (value) - { - this._bottomHeight = value; - let uvs = this.uvs; - let vertices = this.vertices; - uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; - vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; - this.dirty=true; - } + get bottomHeight() + { + return this._bottomHeight; } -}); + set bottomHeight(value) + { + this._bottomHeight = value; + let uvs = this.uvs; + let vertices = this.vertices; + uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - this._uvh * value; + vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - value; + this.dirty=true; + } +} + +export default NineSlicePlane; \ No newline at end of file diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 21f6275..a1d7cdc 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -1,4 +1,4 @@ -let Mesh = require('./Mesh'); +import Mesh from './Mesh'; /** * The Plane allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {number} verticesY - The number of vertices in the y-axis * */ -class Plane extends Mesh { +class Plane extends Mesh +{ constructor(texture, verticesX, verticesY) { super(texture); @@ -118,4 +119,4 @@ } -module.exports = Plane; +export default Plane; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f5077d8..e67b1af 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,5 +1,5 @@ -let Mesh = require('./Mesh'); -let core = require('../core'); +import Mesh from './Mesh'; +import core from '../core'; /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -18,7 +18,8 @@ * @param {PIXI.Point[]} points - An array of {@link PIXI.Point} objects to construct this rope. * */ -class Rope extends Mesh { +class Rope extends Mesh +{ constructor(texture, points) { super(texture); @@ -209,4 +210,4 @@ } -module.exports = Rope; +export default Rope; diff --git a/src/mesh/index.js b/src/mesh/index.js index 9bf2a76..c45dffe 100644 --- a/src/mesh/index.js +++ b/src/mesh/index.js @@ -1,17 +1,16 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import Mesh from './Mesh'; +import Plane from './Plane'; +import NineSlicePlane from './NineSlicePlane'; +import Rope from './Rope'; +import MeshShader from './webgl/MeshShader'; /** * @namespace PIXI.mesh */ -module.exports = { - Mesh: require('./Mesh'), - Plane: require('./Plane'), - NineSlicePlane: require('./NineSlicePlane'), - Rope: require('./Rope'), - MeshShader: require('./webgl/MeshShader') +export default { + Mesh, + Plane, + NineSlicePlane, + Rope, + MeshShader }; diff --git a/src/mesh/webgl/MeshShader.js b/src/mesh/webgl/MeshShader.js index 13e1766..04fa90f 100644 --- a/src/mesh/webgl/MeshShader.js +++ b/src/mesh/webgl/MeshShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI.mesh * @param gl {PIXI.Shader} TODO: Find a good explanation for this. */ -class MeshShader extends Shader { +class MeshShader extends Shader +{ constructor(gl) { super( @@ -42,4 +43,4 @@ } } -module.exports = MeshShader; +export default MeshShader; \ No newline at end of file diff --git a/src/particles/ParticleContainer.js b/src/particles/ParticleContainer.js index 52b37c1..5161e02 100644 --- a/src/particles/ParticleContainer.js +++ b/src/particles/ParticleContainer.js @@ -1,4 +1,4 @@ -let core = require('../core'); +import core from '../core'; /** * The ParticleContainer class is a really fast version of the Container built solely for speed, @@ -32,7 +32,8 @@ * @param [properties.alpha=false] {boolean} When true, alpha be uploaded and applied. * @param [batchSize=15000] {number} Number of particles per batch. */ -class ParticleContainer extends core.Container { +class ParticleContainer extends core.Container +{ constructor(maxSize, properties, batchSize) { super(); @@ -330,4 +331,4 @@ } -module.exports = ParticleContainer; +export default ParticleContainer; diff --git a/src/particles/index.js b/src/particles/index.js index 68d4dc7..657a984 100644 --- a/src/particles/index.js +++ b/src/particles/index.js @@ -1,14 +1,10 @@ -/** - * @file Main export of the PIXI extras library - * @author Mat Groves - * @copyright 2013-2015 GoodBoyDigital - * @license {@link https://github.com/pixijs/pixi.js/blob/master/LICENSE|MIT License} - */ +import ParticleContainer from './ParticleContainer'; +import ParticleRenderer from './webgl/ParticleRenderer'; /** * @namespace PIXI.particles */ -module.exports = { - ParticleContainer: require('./ParticleContainer'), - ParticleRenderer: require('./webgl/ParticleRenderer') +export default { + ParticleContainer, + ParticleRenderer }; diff --git a/src/particles/webgl/ParticleBuffer.js b/src/particles/webgl/ParticleBuffer.js index ecbd63d..6808183 100644 --- a/src/particles/webgl/ParticleBuffer.js +++ b/src/particles/webgl/ParticleBuffer.js @@ -1,5 +1,5 @@ -let glCore = require('pixi-gl-core'), - createIndicesForQuads = require('../../core/utils/createIndicesForQuads'); +import glCore from 'pixi-gl-core'; +import createIndicesForQuads from '../../core/utils/createIndicesForQuads'; /** * @author Mat Groves @@ -19,7 +19,8 @@ * @private * @memberof PIXI */ -class ParticleBuffer { +class ParticleBuffer +{ constructor(gl, properties, dynamicPropertyFlags, size) { /** @@ -228,4 +229,4 @@ } -module.exports = ParticleBuffer; +export default ParticleBuffer; diff --git a/src/particles/webgl/ParticleRenderer.js b/src/particles/webgl/ParticleRenderer.js index b416c1c..8fe6acf 100644 --- a/src/particles/webgl/ParticleRenderer.js +++ b/src/particles/webgl/ParticleRenderer.js @@ -1,6 +1,6 @@ -let core = require('../../core'), - ParticleShader = require('./ParticleShader'), - ParticleBuffer = require('./ParticleBuffer'); +import core from '../../core'; +import ParticleShader from './ParticleShader'; +import ParticleBuffer from './ParticleBuffer'; /** * @author Mat Groves @@ -20,7 +20,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} The renderer this sprite batch works for. */ -class ParticleRenderer extends core.ObjectRenderer { +class ParticleRenderer extends core.ObjectRenderer +{ constructor(renderer) { super(renderer); @@ -426,6 +427,6 @@ } -module.exports = ParticleRenderer; +export default ParticleRenderer; core.WebGLRenderer.registerPlugin('particle', ParticleRenderer); diff --git a/src/particles/webgl/ParticleShader.js b/src/particles/webgl/ParticleShader.js index 684413b..5127bdb 100644 --- a/src/particles/webgl/ParticleShader.js +++ b/src/particles/webgl/ParticleShader.js @@ -1,4 +1,4 @@ -let Shader = require('../../core/Shader'); +import Shader from '../../core/Shader'; /** * @class @@ -6,7 +6,8 @@ * @memberof PIXI * @param gl {PIXI.Shader} The webgl shader manager this shader works for. */ -class ParticleShader extends Shader { +class ParticleShader extends Shader +{ constructor(gl) { super( @@ -60,4 +61,4 @@ } } -module.exports = ParticleShader; +export default ParticleShader; diff --git a/src/prepare/canvas/CanvasPrepare.js b/src/prepare/canvas/CanvasPrepare.js index b8a3682..ac5cc9d 100644 --- a/src/prepare/canvas/CanvasPrepare.js +++ b/src/prepare/canvas/CanvasPrepare.js @@ -1,4 +1,4 @@ -let core = require('../../core'); +import core from '../../core'; /** * Prepare uploads elements to the GPU. The CanvasRenderer version of prepare @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.CanvasRenderer} A reference to the current renderer */ -class CanvasPrepare { +class CanvasPrepare +{ constructor() { } @@ -53,9 +54,8 @@ destroy() { } - } -module.exports = CanvasPrepare; - core.CanvasRenderer.registerPlugin('prepare', CanvasPrepare); + +export default CanvasPrepare; \ No newline at end of file diff --git a/src/prepare/index.js b/src/prepare/index.js index 962e362..066a4a6 100644 --- a/src/prepare/index.js +++ b/src/prepare/index.js @@ -1,5 +1,7 @@ +import webGL from './webgl/WebGLPrepare'; +import canvas from './canvas/CanvasPrepare'; -module.exports = { - webGL: require('./webgl/WebGLPrepare'), - canvas: require('./canvas/CanvasPrepare') +export default { + webGL, + canvas }; \ No newline at end of file diff --git a/src/prepare/webgl/WebGLPrepare.js b/src/prepare/webgl/WebGLPrepare.js index bac893f..de01915 100644 --- a/src/prepare/webgl/WebGLPrepare.js +++ b/src/prepare/webgl/WebGLPrepare.js @@ -1,5 +1,5 @@ -let core = require('../../core'), - SharedTicker = core.ticker.shared; +import core from '../../core'; +const SharedTicker = core.ticker.shared; /** * The prepare manager provides functionality to upload content to the GPU @@ -7,7 +7,8 @@ * @memberof PIXI * @param renderer {PIXI.WebGLRenderer} A reference to the current renderer */ -class WebGLPrepare { +class WebGLPrepare +{ constructor(renderer) { /** @@ -221,8 +222,6 @@ */ WebGLPrepare.UPLOADS_PER_FRAME = 4; -module.exports = WebGLPrepare; - /** * Built-in hook to upload PIXI.Texture objects to the GPU * @private @@ -303,3 +302,5 @@ } core.WebGLRenderer.registerPlugin('prepare', WebGLPrepare); + +export default WebGLPrepare; \ No newline at end of file